From 425ed2e5764f963afed04ae07f606106bc40f4d1 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 12 Nov 2026 19:03:35 -0300 Subject: [PATCH] The error codes spin writes, held to spin's own list spin v20261110.01, the release versions.yaml pins, writes key_not_enrolled (add_key, with the keys page as url) and no_extension_release, and no longer writes access_needs_signature, keyring_needs_signature or no_key_held (spin 22c480b66). The contract still had the old three, so key_not_enrolled was an envelope isErrorEnvelope refused and the extension showed as internal. The contract, the errors module and the fake spin now have spin's codes: key_not_enrolled takes no_key_held's Add Key, `spin ssh-key add` in a terminal, which has the passkey confirm the key; no_extension_release is shown whole, as no_vscode_server is. The keyring signing flow and its button go. hack/errcodes holds ACTION_OF to errorActions in spin's cmd/cli/cmd/errcode.go, code and action both ways; task contract:spin reads that file at the pinned release over git, and the Bump spin workflow runs it after the bump, with the read token, so a release that adds or drops a code fails the bump. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/bump-spin.yml | 6 ++ CONTRIBUTING.md | 11 +- Taskfile.yml | 15 +++ hack/errcodes/main.go | 172 ++++++++++++++++++++++++++++++++ hack/errcodes/main_test.go | 144 ++++++++++++++++++++++++++ src/cli/contract.ts | 26 +++-- src/errors/index.ts | 48 +++------ test/fake-spin/spin.cjs | 9 +- test/unit/cli-client.test.ts | 4 +- test/unit/contract.test.ts | 10 +- test/unit/errors.test.ts | 66 +++--------- test/unit/open.test.ts | 6 +- 12 files changed, 398 insertions(+), 119 deletions(-) create mode 100644 hack/errcodes/main.go create mode 100644 hack/errcodes/main_test.go diff --git a/.github/workflows/bump-spin.yml b/.github/workflows/bump-spin.yml index e280f3f..676569b 100644 --- a/.github/workflows/bump-spin.yml +++ b/.github/workflows/bump-spin.yml @@ -80,6 +80,12 @@ jobs: RELEASE: ${{ steps.newer.outputs.release }} run: go tool task spin:bump + - name: Error codes + if: steps.newer.outputs.release != '' + env: + GH_TOKEN: ${{ steps.read.outputs.token }} + run: go tool task contract:spin + - name: Check if: steps.newer.outputs.release != '' run: go tool task ci diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ba5ef23..c76f516 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,9 +31,13 @@ run is named `spin `, which is how shipset finds it again). The run: 1. stops, successfully, when the release is not newer than the pin (`task spin:newer`); 2. bumps the pin (`task spin:bump`, go-tools' `versions bump spin `), reading the tag's commit from spin with a read-only token of the release app; -3. runs `task ci` and `task package:all`, which pulls that release's CLI for every platform it has +3. holds `src/cli/contract.ts`'s error codes and actions to errorActions in that release's + `cmd/cli/cmd/errcode.go` (`task contract:spin`, `hack/errcodes`), with the same token: a code + spin added or dropped fails the run, and the contract, the errors module and the fake spin + follow it by hand; +4. runs `task ci` and `task package:all`, which pulls that release's CLI for every platform it has one for and checks each with cosign; -4. moves `package.json`'s version to the next patch when a tag has it already, commits that and +5. moves `package.json`'s version to the next patch when a tag has it already, commits that and the pin as the release app (spin-stack-release), force-pushes `spin/next`, and opens the pull request there, or rewrites the one open (`task spin:propose`, `hack/spinpropose`). @@ -44,7 +48,8 @@ CI and Package run on it. Merging it, after checking the CLI's contract against person's, and it releases the extension: `.github/workflows/tag.yml` tags the merge (below). The run needs the app's key as the secret `RELEASE_APP_KEY`. -To bump by hand, `go tool task spin:bump RELEASE=` and `go tool task package:all`. +To bump by hand, `go tool task spin:bump RELEASE=`, `go tool task contract:spin` and +`go tool task package:all`. ## Releasing diff --git a/Taskfile.yml b/Taskfile.yml index 2a7955a..792b05d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -184,6 +184,21 @@ tasks: - '[ -z "${GH_TOKEN:-}" ] || gh auth setup-git' - versions bump spin "{{.RELEASE}}" + contract:spin: + desc: Hold src/cli/contract.ts's error codes and actions to errorActions in spin's cmd/cli/cmd/errcode.go at the release versions.yaml pins (hack/errcodes), read from spin's repository over git - with GH_TOKEN as git's credentials when it is set, since spin is private. The Bump spin workflow runs it after the bump, so a release that adds or drops a code is a red bump, not an envelope read as internal. + vars: + SPIN: + sh: versions version spin + cmds: + - '[ -z "${GH_TOKEN:-}" ] || gh auth setup-git' + - | + set -eu + dir=$(mktemp -d) + trap 'rm -rf "$dir"' EXIT + git clone --quiet --depth 1 --branch {{.SPIN}} --filter=blob:none --no-checkout https://github.com/spin-stack/spin "$dir/spin" + git -C "$dir/spin" show HEAD:cmd/cli/cmd/errcode.go > "$dir/errcode.go" + go run ./hack/errcodes -spin "$dir/errcode.go" -contract src/cli/contract.ts + spin:propose: desc: Commit versions.yaml's spin at RELEASE, with package.json at the next patch when its version is tagged already, push it to spin/next and open or rewrite the pull request there, as the app GH_TOKEN and APP_SLUG name (hack/spinpropose) - the Bump spin workflow's last step, after task ci and task package:all. requires: diff --git a/hack/errcodes/main.go b/hack/errcodes/main.go new file mode 100644 index 0000000..422188b --- /dev/null +++ b/hack/errcodes/main.go @@ -0,0 +1,172 @@ +// Command errcodes holds the extension's error codes to the spin CLI's: every code, and the action +// it pairs with, in errorActions of spin's cmd/cli/cmd/errcode.go is ACTION_OF in +// src/cli/contract.ts, and nothing else is. A code spin adds or drops is a failure here, not an +// envelope the extension quietly reads as internal (task contract:spin reads spin's file at the +// release versions.yaml pins): +// +// go run ./hack/errcodes -spin errcode.go -contract src/cli/contract.ts +package main + +import ( + "errors" + "flag" + "fmt" + "go/ast" + "go/parser" + "go/token" + "os" + "regexp" + "sort" + "strconv" + "strings" +) + +func main() { + spinPath := flag.String("spin", "", "spin's cmd/cli/cmd/errcode.go") + contractPath := flag.String("contract", "src/cli/contract.ts", "the extension's contract") + flag.Parse() + if err := check(*spinPath, *contractPath); err != nil { + fmt.Fprintln(os.Stderr, "errcodes:", err) + os.Exit(1) + } + fmt.Println("errcodes: the contract's codes are spin's") +} + +func check(spinPath, contractPath string) error { + spinSrc, err := os.ReadFile(spinPath) + if err != nil { + return err + } + contractSrc, err := os.ReadFile(contractPath) + if err != nil { + return err + } + spin, err := spinActions(spinSrc) + if err != nil { + return fmt.Errorf("%s: %w", spinPath, err) + } + contract, err := contractActions(string(contractSrc)) + if err != nil { + return fmt.Errorf("%s: %w", contractPath, err) + } + if d := diff(spin, contract); len(d) > 0 { + return errors.New("the contract is not spin's:\n " + strings.Join(d, "\n ")) + } + return nil +} + +// spinActions reads errorActions: each key a constant of type errorCode, each value its action. +func spinActions(src []byte) (map[string]string, error) { + f, err := parser.ParseFile(token.NewFileSet(), "errcode.go", src, 0) + if err != nil { + return nil, err + } + codes := map[string]string{} + var table *ast.CompositeLit + for _, decl := range f.Decls { + gen, ok := decl.(*ast.GenDecl) + if !ok { + continue + } + for _, spec := range gen.Specs { + vs, ok := spec.(*ast.ValueSpec) + if !ok { + continue + } + for i, name := range vs.Names { + if i >= len(vs.Values) { + continue + } + switch gen.Tok { + case token.CONST: + if s, ok := stringLit(vs.Values[i]); ok { + codes[name.Name] = s + } + case token.VAR: + if lit, ok := vs.Values[i].(*ast.CompositeLit); ok && name.Name == "errorActions" { + table = lit + } + } + } + } + } + if table == nil { + return nil, errors.New("no errorActions") + } + actions := map[string]string{} + for _, elt := range table.Elts { + kv, ok := elt.(*ast.KeyValueExpr) + if !ok { + return nil, errors.New("errorActions holds an entry that is no key and value") + } + key, ok := kv.Key.(*ast.Ident) + if !ok { + return nil, errors.New("errorActions has a key that is no constant") + } + code, ok := codes[key.Name] + if !ok { + return nil, fmt.Errorf("errorActions names %s, which is no string constant", key.Name) + } + action, ok := stringLit(kv.Value) + if !ok { + return nil, fmt.Errorf("errorActions pairs %s with no string", code) + } + actions[code] = action + } + return actions, nil +} + +func stringLit(e ast.Expr) (string, bool) { + lit, ok := e.(*ast.BasicLit) + if !ok || lit.Kind != token.STRING { + return "", false + } + s, err := strconv.Unquote(lit.Value) + return s, err == nil +} + +var ( + tableStart = regexp.MustCompile(`(?m)^export const ACTION_OF = \{$`) + tableEntry = regexp.MustCompile(`^\s*([a-z_]+): "([a-z_]+)",?$`) +) + +// contractActions reads ACTION_OF, one `code: "action",` to a line, up to its closing brace. +func contractActions(src string) (map[string]string, error) { + start := tableStart.FindStringIndex(src) + if start == nil { + return nil, errors.New("no ACTION_OF") + } + actions := map[string]string{} + for _, line := range strings.Split(src[start[1]:], "\n")[1:] { + if strings.HasPrefix(line, "}") { + return actions, nil + } + m := tableEntry.FindStringSubmatch(line) + if m == nil { + return nil, fmt.Errorf("ACTION_OF holds %q, which is no `code: \"action\",`", line) + } + actions[m[1]] = m[2] + } + return nil, errors.New("ACTION_OF does not end") +} + +// diff says, sorted, each code one side has and the other lacks, and each the two pair otherwise. +func diff(spin, contract map[string]string) []string { + var out []string + for code, action := range spin { + got, ok := contract[code] + switch { + case !ok: + out = append(out, fmt.Sprintf("spin writes %s (%s), which the contract lacks", code, action)) + case got != action: + out = append(out, fmt.Sprintf("%s: spin pairs %s, the contract %s", code, action, got)) + } + } + for code := range contract { + if _, ok := spin[code]; !ok { + out = append(out, fmt.Sprintf("the contract has %s, which spin no longer writes", code)) + } + } + sort.Strings(out) + return out +} diff --git a/hack/errcodes/main_test.go b/hack/errcodes/main_test.go new file mode 100644 index 0000000..b48c0ef --- /dev/null +++ b/hack/errcodes/main_test.go @@ -0,0 +1,144 @@ +package main + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +// spinSrc is errcode.go as spin writes it: the codes, then errorActions. +const spinSrc = `package cmd + +type errorCode string + +const ( + codeNotSignedIn errorCode = "not_signed_in" + // The key this machine logs in with is none the control plane certifies. + codeKeyNotEnrolled errorCode = "key_not_enrolled" + codeInternal errorCode = "internal" +) + +const muxPersist = "10m" + +var errorActions = map[errorCode]string{ + codeNotSignedIn: "login", + codeKeyNotEnrolled: "add_key", + codeInternal: "details", +} +` + +const contractSrc = `export type Action = "login" | "add_key" | "details" + +export const ACTION_OF = { + not_signed_in: "login", + key_not_enrolled: "add_key", + internal: "details", +} as const satisfies Record +` + +func TestSpinActions(t *testing.T) { + got, err := spinActions([]byte(spinSrc)) + if err != nil { + t.Fatal(err) + } + want := map[string]string{"not_signed_in": "login", "key_not_enrolled": "add_key", "internal": "details"} + if len(got) != len(want) { + t.Fatalf("got %v, want %v", got, want) + } + for k, v := range want { + if got[k] != v { + t.Errorf("%s: got %q, want %q", k, got[k], v) + } + } +} + +func TestContractActions(t *testing.T) { + got, err := contractActions(contractSrc) + if err != nil { + t.Fatal(err) + } + if len(got) != 3 || got["key_not_enrolled"] != "add_key" { + t.Fatalf("got %v", got) + } +} + +// The contract this repository holds parses: the check is never green for reading nothing. +func TestTheContractParses(t *testing.T) { + src, err := os.ReadFile(filepath.Join("..", "..", "src", "cli", "contract.ts")) + if err != nil { + t.Fatal(err) + } + got, err := contractActions(string(src)) + if err != nil { + t.Fatal(err) + } + if got["internal"] != "details" { + t.Fatalf("ACTION_OF read as %v", got) + } +} + +func TestDiff(t *testing.T) { + for _, tc := range []struct { + name string + contract string + want []string + }{ + {name: "the same", contract: contractSrc}, + { + name: "a code spin added", + contract: strings.Replace(contractSrc, " key_not_enrolled: \"add_key\",\n", "", 1), + want: []string{"spin writes key_not_enrolled (add_key), which the contract lacks"}, + }, + { + name: "a code spin dropped", + contract: strings.Replace(contractSrc, " internal:", " no_key_held: \"add_key\",\n internal:", 1), + want: []string{"the contract has no_key_held, which spin no longer writes"}, + }, + { + name: "another action", + contract: strings.Replace(contractSrc, `not_signed_in: "login"`, `not_signed_in: "details"`, 1), + want: []string{"not_signed_in: spin pairs login, the contract details"}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + spin, err := spinActions([]byte(spinSrc)) + if err != nil { + t.Fatal(err) + } + contract, err := contractActions(tc.contract) + if err != nil { + t.Fatal(err) + } + got := diff(spin, contract) + if strings.Join(got, "|") != strings.Join(tc.want, "|") { + t.Fatalf("got %q, want %q", got, tc.want) + } + }) + } +} + +func TestRefused(t *testing.T) { + for _, tc := range []struct{ name, spin, contract, want string }{ + {"no table in spin", "package cmd\n", contractSrc, "no errorActions"}, + {"a key that is no constant", strings.Replace(spinSrc, "codeInternal: \"details\"", "\"internal\": \"details\"", 1), contractSrc, "no constant"}, + {"no table in the contract", spinSrc, "export const X = {}\n", "no ACTION_OF"}, + {"an entry that is no pair", spinSrc, strings.Replace(contractSrc, ` internal: "details",`, ` ...MORE,`, 1), "no `code"}, + {"a table that does not end", spinSrc, "export const ACTION_OF = {\n internal: \"details\",", "does not end"}, + } { + t.Run(tc.name, func(t *testing.T) { + dir := t.TempDir() + spin, contract := filepath.Join(dir, "errcode.go"), filepath.Join(dir, "contract.ts") + if err := os.WriteFile(spin, []byte(tc.spin), 0o600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(contract, []byte(tc.contract), 0o600); err != nil { + t.Fatal(err) + } + err := check(spin, contract) + if err == nil || !strings.Contains(err.Error(), tc.want) { + t.Fatalf("got %v, want an error holding %q", err, tc.want) + } + }) + } +} diff --git a/src/cli/contract.ts b/src/cli/contract.ts index c6073c8..888b1d3 100644 --- a/src/cli/contract.ts +++ b/src/cli/contract.ts @@ -3,19 +3,21 @@ // writes two lines), and a failure is one ErrorEnvelope on stdout with exit 1. These types are the // whole of what the extension reads; a field the CLI adds is ignored until a type here names it. -// Each code, and the one action the CLI pairs with it. The CLI's list is cmd/cli/cmd/errcode.go. +// Each code, and the one action the CLI pairs with it. The CLI's list is errorActions in its +// cmd/cli/cmd/errcode.go, which `task contract:spin` (hack/errcodes) holds ACTION_OF to at the +// release versions.yaml pins. export type ErrorCode = | "cli_outdated" | "not_signed_in" | "workspace_stopped" | "workspace_failed" - | "access_needs_signature" - // This machine holds a key the caller registered that their keyring does not list yet. - | "keyring_needs_signature" - // This machine holds none of the caller's registered keys. - | "no_key_held" + // The key this machine logs in with is none the installation certifies for the caller: adding + // it, with their passkey, lets it in. + | "key_not_enrolled" | "no_capacity" | "unreachable" + // No release of this extension carries the CLI's release (`spin vscode install`). + | "no_extension_release" // The workspace has no server for this VS Code, could not be given one, and has no room for // the one VS Code would download: opened, Remote-SSH would reconnect without end. | "no_vscode_server" @@ -26,8 +28,6 @@ export type Action = | "login" | "start" | "open_dashboard" - | "sign" - | "sign_keyring" | "add_key" | "retry" | "details" @@ -38,11 +38,10 @@ export const ACTION_OF = { not_signed_in: "login", workspace_stopped: "start", workspace_failed: "open_dashboard", - access_needs_signature: "sign", - keyring_needs_signature: "sign_keyring", - no_key_held: "add_key", + key_not_enrolled: "add_key", no_capacity: "retry", unreachable: "retry", + no_extension_release: "details", no_vscode_server: "details", internal: "details", } as const satisfies Record @@ -57,9 +56,8 @@ export interface ErrorEnvelope { // The release the installation runs, with cli_outdated. release?: string workspace_id?: string - // A page that resolves it: the signature page for access_needs_signature, the page where a - // passkey signs the keyring for keyring_needs_signature, the workspace's dashboard page for - // workspace_failed. + // A page that resolves it: the keys page, behind a passkey, for key_not_enrolled; the + // workspace's dashboard page for workspace_failed. url?: string } } diff --git a/src/errors/index.ts b/src/errors/index.ts index 12ddba5..a3c4900 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -39,7 +39,6 @@ export const BUTTON = { signIn: "Sign In", start: "Start", dashboard: "Open in Dashboard", - sign: "Sign in Browser", addKey: "Add Key", retry: "Retry", } as const @@ -93,14 +92,11 @@ async function show(error: unknown, retry: Retry | undefined, updated: boolean): ) case "workspace_failed": return offerUrl(withReason(TEXT.workspace_failed, e.message), BUTTON.dashboard, e.url) - case "access_needs_signature": - return offerUrl(TEXT.access_needs_signature, BUTTON.sign, e.url) - case "keyring_needs_signature": - return signKeyring(e.url, retry === undefined ? undefined : () => again()) - case "no_key_held": + case "key_not_enrolled": // A key is worth adding with nothing to run again: the next command finds it. if ( - (await vscode.window.showErrorMessage(TEXT.no_key_held, BUTTON.addKey)) === BUTTON.addKey + (await vscode.window.showErrorMessage(TEXT.key_not_enrolled, BUTTON.addKey)) === + BUTTON.addKey ) { try { await addKey(() => again()) @@ -113,6 +109,8 @@ async function show(error: unknown, retry: Retry | undefined, updated: boolean): case "no_capacity": case "unreachable": return offer(vscode.window.showErrorMessage, TEXT[e.code], BUTTON.retry, retry, () => again()) + case "no_extension_release": + return internal(e, traceId, TEXT.no_extension_release) case "no_vscode_server": // The message is what was refused and what resolves it - an administrator's publish, or // more room - so it is shown whole, with what internal offers beside it. @@ -128,38 +126,16 @@ export const TEXT = { not_signed_in: "You are signed out of Spinbox. Sign in to continue.", workspace_stopped: "This workspace is stopped. Start it to open it.", workspace_failed: "This workspace failed. Open it in the dashboard to see why.", - access_needs_signature: - "This workspace needs your signature. Sign in the browser, then try again.", - keyring_needs_signature: - "Your keyring does not list this machine's key yet. Sign it in the browser, then try again.", - no_key_held: "This machine holds none of your SSH keys. Add one to your account to connect.", + key_not_enrolled: + "The key this machine connects with is not on your account. Add it, with your passkey, to connect.", no_capacity: "No host has room for this workspace right now. Try again in a moment.", unreachable: "Spinbox cannot reach the installation. Check your connection and try again.", + no_extension_release: "No release of the Spinbox extension carries this spin CLI's release.", no_vscode_server: "This workspace has no server for your VS Code, and no room to download one.", internal: "Spinbox hit an unexpected error.", } as const satisfies Record -// Shown once the signing page is open, for the person to come back to. -export const KEYRING_SIGNED = "Once your keyring is signed in the browser, retry." - -// keyring_needs_signature: the keyring is signed in the browser, away from VS Code, so what the -// person comes back to is a notification that runs the command again once they have. -async function signKeyring(url: string | undefined, again: (() => Promise) | undefined) { - const buttons = url === undefined ? [] : [BUTTON.sign] - const choice = await vscode.window.showErrorMessage(TEXT.keyring_needs_signature, ...buttons) - if (choice !== BUTTON.sign || url === undefined) { - return - } - await vscode.env.openExternal(vscode.Uri.parse(url)) - if ( - again !== undefined && - (await vscode.window.showInformationMessage(KEYRING_SIGNED, BUTTON.retry)) === BUTTON.retry - ) { - await again() - } -} - -// The public key spin connects with where the keyring lists none of this machine's: the first of +// The public key spin connects with where the account has none of this machine's: the first of // the usual ones in ~/.ssh, or spin's own (cmd/cli/cmd/ssh.go, usualIdentity). Undefined when this // machine has none of them. export function keyToAdd(home: string): string | undefined { @@ -171,9 +147,9 @@ export function keyToAdd(home: string): string | undefined { ].find((p) => existsSync(p)) } -// no_key_held: `spin ssh-key add` in a terminal, named for this machine, with the key spin -// connects with. At a terminal it goes on to get the keyring signed - here, or with a passkey in -// the browser - which only a person can finish, so it is run there and not by the extension. With +// key_not_enrolled: `spin ssh-key add` in a terminal, named for this machine, with the key spin +// connects with. It opens the page where the person's passkey confirms the key, and waits - which +// only a person can finish, so it is run there and not by the extension. With // no key to add, the terminal has the command that makes one and adds it, ready to run. The // command runs again once the terminal ends with exit 0. async function addKey(again: () => Promise): Promise { diff --git a/test/fake-spin/spin.cjs b/test/fake-spin/spin.cjs index a396fd8..b3d7e2d 100755 --- a/test/fake-spin/spin.cjs +++ b/test/fake-spin/spin.cjs @@ -28,11 +28,10 @@ const ACTION_OF = { not_signed_in: "login", workspace_stopped: "start", workspace_failed: "open_dashboard", - access_needs_signature: "sign", - keyring_needs_signature: "sign_keyring", - no_key_held: "add_key", + key_not_enrolled: "add_key", no_capacity: "retry", unreachable: "retry", + no_extension_release: "details", no_vscode_server: "details", internal: "details", } @@ -173,9 +172,7 @@ function envelope(code, extra) { message: `fake ${code}`, action: ACTION_OF[code], ...(code === "cli_outdated" ? { release: "v20261105.01" } : {}), - ...(code === "keyring_needs_signature" - ? { url: "https://term.spinbox.test/#/sign" } - : {}), + ...(code === "key_not_enrolled" ? { url: `${ENDPOINT}/settings/keys` } : {}), ...fields, }, }, diff --git a/test/unit/cli-client.test.ts b/test/unit/cli-client.test.ts index 2ffe94a..1419351 100644 --- a/test/unit/cli-client.test.ts +++ b/test/unit/cli-client.test.ts @@ -141,10 +141,10 @@ describe("ProcessSpinCli failures", () => { }) it("keeps the envelope's fields", async () => { - scenario({ code: { error: "access_needs_signature", url: "https://app.spinbox.test/s" } }) + scenario({ code: { error: "key_not_enrolled", url: "https://app.spinbox.test/settings/keys" } }) const e = (await rejection(cli().cli.code("my-ws", undefined, "a".repeat(40)))) as CliError expect(e.envelope.error).toMatchObject({ - code: "access_needs_signature", + code: "key_not_enrolled", url: expect.any(String), }) }) diff --git a/test/unit/contract.test.ts b/test/unit/contract.test.ts index 9de7033..cf37189 100644 --- a/test/unit/contract.test.ts +++ b/test/unit/contract.test.ts @@ -63,7 +63,7 @@ describe("fake spin", () => { writeFileSync( scenario, JSON.stringify({ - code: { error: "access_needs_signature", url: "https://app.spinbox.test/sign/ws-1" }, + code: { error: "key_not_enrolled", url: "https://app.spinbox.test/settings/keys?x=1" }, }), ) const env = { FAKE_SPIN_SCENARIO: scenario } @@ -72,10 +72,10 @@ describe("fake spin", () => { expect(r.docs).toEqual([ { error: { - code: "access_needs_signature", - action: "sign", - message: "fake access_needs_signature", - url: "https://app.spinbox.test/sign/ws-1", + code: "key_not_enrolled", + action: "add_key", + message: "fake key_not_enrolled", + url: "https://app.spinbox.test/settings/keys?x=1", }, }, ]) diff --git a/test/unit/errors.test.ts b/test/unit/errors.test.ts index 40d4511..1d65950 100644 --- a/test/unit/errors.test.ts +++ b/test/unit/errors.test.ts @@ -5,15 +5,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest" import { CliError } from "../../src/cli/client" import type { ErrorCode, ErrorEnvelope } from "../../src/cli/contract" import { ACTION_OF, ERROR_CODES } from "../../src/cli/contract" -import { - BUTTON, - configureErrors, - KEYRING_SIGNED, - keyToAdd, - type Retry, - showCliError, - TEXT, -} from "../../src/errors" +import { BUTTON, configureErrors, keyToAdd, type Retry, showCliError, TEXT } from "../../src/errors" const vs = vi.hoisted(() => ({ showErrorMessage: vi.fn(), @@ -109,7 +101,6 @@ interface Case { } const URL = "https://app.spinbox.test/w/ws-1" -const SIGN_URL = "https://term.spinbox.test/#/sign" const CASES: Case[] = [ { @@ -144,30 +135,12 @@ const CASES: Case[] = [ did: () => expect(String(vs.openExternal.mock.calls[0]?.[0])).toBe(URL), }, { - code: "access_needs_signature", - extra: { url: URL }, - text: TEXT.access_needs_signature, - button: BUTTON.sign, - did: () => expect(String(vs.openExternal.mock.calls[0]?.[0])).toBe(URL), - }, - { - // The page opens, and the notification left behind runs the command again. - code: "keyring_needs_signature", - extra: { url: SIGN_URL }, - setup: () => vs.showInformationMessage.mockResolvedValueOnce(BUTTON.retry), - text: TEXT.keyring_needs_signature, - button: BUTTON.sign, - did: (retry) => { - expect(String(vs.openExternal.mock.calls[0]?.[0])).toBe(SIGN_URL) - expect(vs.showInformationMessage).toHaveBeenCalledWith(KEYRING_SIGNED, BUTTON.retry) - expect(retry).toHaveBeenCalledWith(undefined) - }, - }, - { - // spin ssh-key add runs in a terminal with the key spin connects with; it ending well retries. - code: "no_key_held", + // spin ssh-key add runs in a terminal with the key spin connects with, and has the passkey + // confirm it; it ending well retries. + code: "key_not_enrolled", + extra: { url: "https://app.spinbox.test/settings/keys" }, setup: () => home(".ssh/id_ed25519.pub"), - text: TEXT.no_key_held, + text: TEXT.key_not_enrolled, button: BUTTON.addKey, did: (retry) => { expect(vs.createTerminal).toHaveBeenCalledWith({ @@ -195,6 +168,12 @@ const CASES: Case[] = [ button: BUTTON.retry, did: (retry) => expect(retry).toHaveBeenCalledWith(undefined), }, + { + code: "no_extension_release", + text: `${TEXT.no_extension_release} no_extension_release msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, { // What resolves it is the CLI's message, shown whole. code: "no_vscode_server", @@ -237,33 +216,20 @@ describe("showCliError", () => { expect(output.show).not.toHaveBeenCalled() }) - it("keyring_needs_signature: the page opened and Retry not chosen, runs nothing again", async () => { - const retry = vi.fn() - click(BUTTON.sign) - await showCliError(cliError("keyring_needs_signature", { url: SIGN_URL }), retry) - expect(vs.openExternal).toHaveBeenCalledOnce() - expect(retry).not.toHaveBeenCalled() - }) - - it("keyring_needs_signature: without a url, offers no page to open", async () => { - await showCliError(cliError("keyring_needs_signature"), vi.fn()) - expect(shown().buttons).toEqual([]) - }) - - it("no_key_held: a terminal that did not end well runs nothing again", async () => { + it("key_not_enrolled: a terminal that did not end well runs nothing again", async () => { const retry = vi.fn() home(".ssh/id_ed25519.pub") exitCode = 1 click(BUTTON.addKey) - await showCliError(cliError("no_key_held"), retry) + await showCliError(cliError("key_not_enrolled"), retry) expect(vs.createTerminal).toHaveBeenCalledOnce() expect(retry).not.toHaveBeenCalled() }) - it("no_key_held: with no key, the terminal has the command that makes one and adds it, not run", async () => { + it("key_not_enrolled: with no key, the terminal has the command that makes one and adds it, not run", async () => { const dir = home() click(BUTTON.addKey) - await showCliError(cliError("no_key_held"), vi.fn()) + await showCliError(cliError("key_not_enrolled"), vi.fn()) expect(vs.createTerminal).toHaveBeenCalledWith({ name: "Spinbox: Add Key" }) const made = join(dir, ".ssh", "id_ed25519") const terminal = vs.createTerminal.mock.results[0]?.value as { diff --git a/test/unit/open.test.ts b/test/unit/open.test.ts index cca1dc1..2920681 100644 --- a/test/unit/open.test.ts +++ b/test/unit/open.test.ts @@ -248,14 +248,14 @@ describe("openWorkspace", () => { }) it("hands a failure to the errors module with a retry that runs it again, and opens nothing", async () => { - const { deps, seen } = setup({ FAKE_SPIN_ERROR: "access_needs_signature" }) + const { deps, seen } = setup({ FAKE_SPIN_ERROR: "key_not_enrolled" }) await openWorkspace(deps, { workspace: "ws-1" }) expect(seen.opened).toEqual([]) expect(seen.cliErrors).toHaveLength(1) const [{ error, retry }] = seen.cliErrors as [Seen["cliErrors"][number]] expect(error).toBeInstanceOf(CliError) - expect((error as CliError).code).toBe("access_needs_signature") - await expect(retry()).rejects.toMatchObject({ code: "access_needs_signature" }) + expect((error as CliError).code).toBe("key_not_enrolled") + await expect(retry()).rejects.toMatchObject({ code: "key_not_enrolled" }) expect(seen.invocations()).toHaveLength(2) expect(seen.cliErrors).toHaveLength(1) })