Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions desktop/e2e/fixtures/mock-devsy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ function defaultState() {
context: "default",
},
],
secrets: [
{ name: "E2E_API_TOKEN", context: "default", backend: "file", availability: "available", attached: true, created: "2026-04-20T08:00:00Z" },
{ name: "E2E_STAGING_TOKEN", context: "staging", backend: "keyring", availability: "available", attached: false },
],
envVars: [
{ name: "E2E_API_URL", context: "default", value: "https://variables.example.test/api", attached: true },
{ name: "E2E_STAGE_NAME", context: "staging", value: "staging", attached: false },
],
tasks: {},
deletedTasks: {},
}
Expand All @@ -86,6 +94,8 @@ function loadState() {
try {
const data = fs.readFileSync(STATE_FILE, "utf8")
const state = JSON.parse(data)
state.secrets ??= defaultState().secrets
state.envVars ??= defaultState().envVars
state.tasks = state.tasks || {}
state.deletedTasks = state.deletedTasks || {}
return state
Expand Down Expand Up @@ -121,6 +131,10 @@ function saveState(state, deletedTaskIds = []) {
const state = loadState()

const rawArgs = process.argv.slice(2)
// Context is a global flag and can precede the root command.
const contextIndex = rawArgs.indexOf("--context")
const variableContext = contextIndex >= 0 ? rawArgs[contextIndex + 1] : "default"
if (contextIndex >= 0) rawArgs.splice(contextIndex, 2)

if (rawArgs[0] === "--version") {
process.stdout.write("v0.1.0-test\n")
Expand Down Expand Up @@ -864,6 +878,30 @@ switch (cmd) {
}
break

case "secret":
case "env": {
const rows = cmd === "secret" ? state.secrets : state.envVars
if (sub === "protection" && extra === "status") {
out({ availability: "available", keySource: "file", remembered: false,
rememberedAvailable: true, fileEntries: state.secrets.filter((row) => row.backend === "file") })
} else if (sub === "list") out(rows)
else if (["set", "delete", "attach", "detach"].includes(sub)) {
const index = rows.findIndex((row) => row.name === extra && row.context === variableContext)
if (sub === "set") {
const row = cmd === "secret"
? { name: extra, context: variableContext, backend: "file", availability: "available", attached: false }
: { name: extra, context: variableContext, value: rawArgs[rawArgs.indexOf("--value") + 1] ?? "", attached: false }
if (cmd === "secret" && rawArgs.includes("--stdin")) fs.readFileSync(0, "utf8")
if (index >= 0) rows[index] = { ...rows[index], ...row, attached: rows[index].attached }
else rows.push(row)
} else if (sub === "delete" && index >= 0) rows.splice(index, 1)
else if (index >= 0) rows[index].attached = sub === "attach"
saveState(state)
out("")
} else out("")
break
}

case "version":
out("v0.1.0-test")
break
Expand Down
134 changes: 134 additions & 0 deletions desktop/e2e/variables.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import type { ElectronApplication, Page } from "@playwright/test"
import { expect, test } from "@playwright/test"
import { launchApp } from "./electron-app.js"

let app: ElectronApplication
let page: Page

async function navigate(hash: string) {
await page.evaluate((route) => {
window.location.hash = route
}, hash)
await expect(
page.getByRole("heading", { name: "Workspace Variables", exact: true }),
).toBeVisible()
}

test.beforeAll(async () => {
;({ app, page } = await launchApp())
})
test.afterAll(async () => {
await app.close()
})

test("unified navigation uses URL tabs and replaces legacy routes", async () => {
const sidebar = page.locator('[data-sidebar="sidebar"]')
await sidebar.locator('a[href="#/variables"]').click()
await expect(
page.getByRole("tab", { name: "Secrets", exact: true }),
).toHaveAttribute("aria-selected", "true")
await expect(
sidebar.locator('a[href="#/secrets"], a[href="#/env"]'),
).toHaveCount(0)
await page
.getByRole("tab", { name: "Environment Variables", exact: true })
.click()
await expect(page).toHaveURL(/#\/variables\?tab=env$/)
await navigate("/secrets")
await expect(page).toHaveURL(/#\/variables\?tab=secrets$/)
await navigate("/env")
await expect(page).toHaveURL(/#\/variables\?tab=env$/)
})

test("legacy keyboard shortcuts select both variables tabs", async () => {
await navigate("/variables?tab=env")
const modifier = process.platform === "darwin" ? "Meta" : "Control"
await page.keyboard.press(`${modifier}+6`)
await expect(page).toHaveURL(/#\/variables\?tab=secrets$/)
await page.keyboard.press(`${modifier}+7`)
await expect(page).toHaveURL(/#\/variables\?tab=env$/)
})

test("environment values start masked and details allow explicit editing", async () => {
await navigate("/variables?tab=env")
const row = page.getByRole("row").filter({ hasText: "E2E_API_URL" })
await expect(row).toContainText("••••••••")
await expect(row).not.toContainText("https://variables.example.test/api")
await row
.getByRole("button", { name: "Show value for E2E_API_URL", exact: true })
.click()
await expect(row).toContainText("https://variables.example.test/api")
await row
.getByRole("button", { name: "Hide value for E2E_API_URL", exact: true })
.click()
await row.getByRole("button", { name: "E2E_API_URL", exact: true }).click()
const details = page.getByRole("dialog", {
name: "Environment variable details",
})
await expect(details).toBeVisible()
await expect(details.getByLabel("Value", { exact: true })).toHaveValue(
"https://variables.example.test/api",
)
await page.keyboard.press("Escape")
await expect(details).not.toBeVisible()
})

test("secret details expose metadata and replacement uses a password input", async () => {
await navigate("/variables?tab=secrets")
const row = page.getByRole("row").filter({ hasText: "E2E_API_TOKEN" })
await row.getByRole("button", { name: "E2E_API_TOKEN", exact: true }).click()
const details = page.getByRole("dialog", { name: "Secret details" })
await expect(details).toContainText("default")
await expect(details).toContainText("Available")
await details.getByRole("button", { name: "Replace secret value" }).click()
const replacement = page.getByRole("dialog", { name: "Replace secret value" })
await expect(
replacement.getByLabel("New value", { exact: true }),
).toHaveAttribute("type", "password")
await replacement.getByRole("button", { name: "Cancel", exact: true }).click()
await page.keyboard.press("Escape")
})

test("add dialogs validate duplicate names and clear canceled secret input", async () => {
await navigate("/variables?tab=secrets")
await page.getByRole("button", { name: "Add secret", exact: true }).click()
const secretDialog = page.getByRole("dialog", {
name: "Add secret",
exact: true,
})
await secretDialog.getByLabel("Name", { exact: true }).fill("E2E_API_TOKEN")
await secretDialog
.getByLabel("Value", { exact: true })
.fill("discarded-secret")
await expect(secretDialog).toContainText(
"A secret with this name already exists",
)
await expect(
secretDialog.getByRole("button", { name: "Save", exact: true }),
).toBeDisabled()
await secretDialog
.getByRole("button", { name: "Cancel", exact: true })
.click()
await page.getByRole("button", { name: "Add secret", exact: true }).click()
await expect(secretDialog.getByLabel("Value", { exact: true })).toHaveValue(
"",
)
await secretDialog
.getByRole("button", { name: "Cancel", exact: true })
.click()
await page
.getByRole("tab", { name: "Environment Variables", exact: true })
.click()
await page.getByRole("button", { name: "Add variable", exact: true }).click()
const envDialog = page.getByRole("dialog", {
name: "Add environment variable",
})
await envDialog.getByLabel("Name", { exact: true }).fill("E2E_API_URL")
await expect(envDialog).toContainText(
"A variable with this name already exists",
)
await expect(
envDialog.getByRole("button", { name: "Save", exact: true }),
).toBeDisabled()
await envDialog.getByRole("button", { name: "Cancel", exact: true }).click()
})
97 changes: 97 additions & 0 deletions desktop/src/main/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,103 @@ describe("CliRunner", () => {
}
})

it("prefers an invocation credential over the session without changing either source", async () => {
const mock = vi.mocked(execFile) as unknown as ReturnType<typeof vi.fn>
mock.mockImplementation(
(_cmd: string, _args: string[], _opts: unknown, callback: ExecCb) =>
callback(null, { stdout: "", stderr: "" }),
)
cli.setSessionPassphrase("session-private")
const env = { DEVSY_SECRETS_PASSPHRASE: "explicit-private" }
await cli.runRaw(["secret", "protection", "remove-passphrase"], { env })
expect(mock.mock.calls[0][2].env.DEVSY_SECRETS_PASSPHRASE).toBe(
"explicit-private",
)
expect(mock.mock.calls[0][1]).not.toContain("explicit-private")
expect(env.DEVSY_SECRETS_PASSPHRASE).toBe("explicit-private")
await cli.runRaw(["secret", "list"])
expect(mock.mock.calls[1][2].env.DEVSY_SECRETS_PASSPHRASE).toBe(
"session-private",
)
})

it.each(["run", "runRaw"] as const)(
"%s preserves unlock errors without invoking the handler when prompting is disabled",
async (method) => {
const mock = vi.mocked(execFile) as unknown as ReturnType<typeof vi.fn>
mock.mockImplementation(
(_cmd: string, _args: string[], _opts: unknown, callback: ExecCb) =>
callback(
Object.assign(new Error("failed"), {
stderr: JSON.stringify({
kind: "error",
outcome: "error",
code: "unlock_required",
message: "Unlock required",
}),
}),
{ stdout: "", stderr: "" },
),
)
const unlock = vi.fn(async () => "private")
cli.setUnlockHandler(unlock)
await expect(
cli[method](["secret", "protection", "remember"], {
allowUnlockPrompt: false,
}),
).rejects.toMatchObject({ cliError: { code: "unlock_required" } })
expect(mock).toHaveBeenCalledOnce()
expect(unlock).not.toHaveBeenCalled()
},
)

it.each(["unlock_required", "unlock_failed"])(
"stdin protection preserves session state on %s and never opens a global prompt",
async (code) => {
const child = fakeChild()
const mockSpawn = vi.mocked(spawn) as unknown as ReturnType<typeof vi.fn>
mockSpawn.mockReturnValue(child)
const unlock = vi.fn(async () => "private")
cli.setUnlockHandler(unlock)
cli.setSessionPassphrase("session-private")
const operation = cli.runRawStdin(
["secret", "protection", "change-passphrase", "--stdin"],
"new-private",
{
allowUnlockPrompt: false,
env: { DEVSY_SECRETS_PASSPHRASE: "old-private" },
},
)
const rejected = expect(operation).rejects.toMatchObject({
cliError: {
code,
message: "Failed *** with ***",
hint: "***",
context: { "***": "***" },
},
})
await vi.waitFor(() => expect(mockSpawn).toHaveBeenCalledOnce())
child.stderr.emit(
"data",
JSON.stringify({
kind: "error",
outcome: "error",
code,
message: "Failed old-private with new-private",
hint: "old-private",
context: { "new-private": "old-private" },
}),
)
child.emit("close", 1)
await rejected
expect(unlock).not.toHaveBeenCalled()
expect(cli.hasSessionPassphrase()).toBe(true)
expect(mockSpawn.mock.calls[0][1]).not.toContain("old-private")
expect(mockSpawn.mock.calls[0][1]).not.toContain("new-private")
expect(child.stdin.written).toBe("new-private")
},
)

it("prompts on a structured unlock requirement and retries exactly once without leaking credentials", async () => {
const mock = vi.mocked(execFile) as unknown as ReturnType<typeof vi.fn>
let attempts = 0
Expand Down
Loading
Loading