From 9c155e32899cd00a38e3d9e91e3c2484ccd615d9 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sun, 29 Nov 2026 09:11:55 -0300 Subject: [PATCH 1/3] cli: read the camelCase -o json spin#1605 writes, and its failure kinds spin-stack/spin#1828 makes -o json one contract: every key camelCase, the error envelope's included, the ssh status file at version 2, and a failure's exit status naming its kind (spin help exit-codes) where it was 1. It adds nine codes to the envelope, which failureKinds in cmd/cli/cmd/exitcodes.go pairs with their actions now that errorActions is gone. The contract types, their callers, the fake spin and the tests read the new keys and statuses. unavailable and timed_out offer Retry; the other new codes show the CLI's message with Show Details and Copy Diagnostics. hack/errcodes reads failureKinds from spin's whole cmd/cli/cmd package, which task contract:spin now checks out sparsely, rather than one file. Closes #60 Co-Authored-By: Claude Opus 5.5 --- Taskfile.yml | 8 +-- hack/errcodes/main.go | 100 ++++++++++++++++++++++------------- hack/errcodes/main_test.go | 78 +++++++++++++++++++++------ src/auth/provider.ts | 6 +-- src/cli/client.ts | 16 +++--- src/cli/contract.ts | 64 +++++++++++++++------- src/errors/index.ts | 24 +++++++-- src/open/open.ts | 8 +-- src/remote/connect.ts | 2 +- src/remote/proxy.ts | 22 ++++---- test/cli/real-spin.test.ts | 13 +++-- test/fake-spin/spin.cjs | 59 ++++++++++++--------- test/unit/auth.test.ts | 2 +- test/unit/cli-client.test.ts | 20 +++---- test/unit/contract.test.ts | 27 +++++----- test/unit/documents.test.ts | 4 +- test/unit/errors.test.ts | 55 +++++++++++++++++++ test/unit/open.test.ts | 24 ++++----- test/unit/proxy.test.ts | 57 ++++++++++++-------- test/unit/status.test.ts | 2 +- 20 files changed, 396 insertions(+), 195 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 43b055a..f7f3622 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -231,7 +231,7 @@ tasks: - versions bump -by 'task spin: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. + desc: Hold src/cli/contract.ts's error codes and actions to failureKinds in spin's cmd/cli/cmd package 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 @@ -241,9 +241,9 @@ tasks: 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 + git -c advice.detachedHead=false clone --quiet --depth 1 --branch {{.SPIN}} --filter=blob:none --sparse https://github.com/spin-stack/spin "$dir/spin" + git -C "$dir/spin" sparse-checkout set cmd/cli/cmd + go run ./hack/errcodes -spin "$dir/spin/cmd/cli/cmd" -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. diff --git a/hack/errcodes/main.go b/hack/errcodes/main.go index 422188b..d678516 100644 --- a/hack/errcodes/main.go +++ b/hack/errcodes/main.go @@ -1,10 +1,11 @@ // 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 +// it pairs with, in failureKinds of spin's cmd/cli/cmd package 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): +// envelope the extension quietly reads as internal (task contract:spin reads spin's package at the +// release versions.yaml pins). The whole package is read, not a file: the codes and the table that +// pairs them live in files of their own, and have moved between them before. // -// go run ./hack/errcodes -spin errcode.go -contract src/cli/contract.ts +// go run ./hack/errcodes -spin /cmd/cli/cmd -contract src/cli/contract.ts package main import ( @@ -15,6 +16,7 @@ import ( "go/parser" "go/token" "os" + "path/filepath" "regexp" "sort" "strconv" @@ -22,18 +24,18 @@ import ( ) func main() { - spinPath := flag.String("spin", "", "spin's cmd/cli/cmd/errcode.go") + spinDir := flag.String("spin", "", "spin's cmd/cli/cmd package directory") contractPath := flag.String("contract", "src/cli/contract.ts", "the extension's contract") flag.Parse() - if err := check(*spinPath, *contractPath); err != nil { + if err := check(*spinDir, *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) +func check(spinDir, contractPath string) error { + spinSrc, err := packageSources(spinDir) if err != nil { return err } @@ -43,7 +45,7 @@ func check(spinPath, contractPath string) error { } spin, err := spinActions(spinSrc) if err != nil { - return fmt.Errorf("%s: %w", spinPath, err) + return fmt.Errorf("%s: %w", spinDir, err) } contract, err := contractActions(string(contractSrc)) if err != nil { @@ -55,61 +57,87 @@ func check(spinPath, contractPath string) error { 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) +// packageSources reads each Go file of dir that is not a test, by name. +func packageSources(dir string) (map[string][]byte, error) { + names, err := filepath.Glob(filepath.Join(dir, "*.go")) if err != nil { return nil, err } + srcs := map[string][]byte{} + for _, name := range names { + if strings.HasSuffix(name, "_test.go") { + continue + } + src, err := os.ReadFile(name) + if err != nil { + return nil, err + } + srcs[filepath.Base(name)] = src + } + if len(srcs) == 0 { + return nil, fmt.Errorf("%s holds no Go file", dir) + } + return srcs, nil +} + +// spinActions reads failureKinds: each row a constant of type errorCode, its action, and the status +// spin exits with, which the extension does not read. The constants may be in any file. +func spinActions(srcs map[string][]byte) (map[string]string, error) { codes := map[string]string{} var table *ast.CompositeLit - for _, decl := range f.Decls { - gen, ok := decl.(*ast.GenDecl) - if !ok { - continue + for name, src := range srcs { + f, err := parser.ParseFile(token.NewFileSet(), name, src, 0) + if err != nil { + return nil, err } - for _, spec := range gen.Specs { - vs, ok := spec.(*ast.ValueSpec) + for _, decl := range f.Decls { + gen, ok := decl.(*ast.GenDecl) if !ok { continue } - for i, name := range vs.Names { - if i >= len(vs.Values) { + for _, spec := range gen.Specs { + vs, ok := spec.(*ast.ValueSpec) + if !ok { continue } - switch gen.Tok { - case token.CONST: - if s, ok := stringLit(vs.Values[i]); ok { - codes[name.Name] = s + for i, name := range vs.Names { + if i >= len(vs.Values) { + continue } - case token.VAR: - if lit, ok := vs.Values[i].(*ast.CompositeLit); ok && name.Name == "errorActions" { - table = lit + 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 == "failureKinds" { + table = lit + } } } } } } if table == nil { - return nil, errors.New("no errorActions") + return nil, errors.New("no failureKinds") } 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") + row, ok := elt.(*ast.CompositeLit) + if !ok || len(row.Elts) < 2 { + return nil, errors.New("failureKinds holds a row that is no {code, action, status}") } - key, ok := kv.Key.(*ast.Ident) + key, ok := row.Elts[0].(*ast.Ident) if !ok { - return nil, errors.New("errorActions has a key that is no constant") + return nil, errors.New("failureKinds has a code 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) + return nil, fmt.Errorf("failureKinds names %s, which is no string constant", key.Name) } - action, ok := stringLit(kv.Value) + action, ok := stringLit(row.Elts[1]) if !ok { - return nil, fmt.Errorf("errorActions pairs %s with no string", code) + return nil, fmt.Errorf("failureKinds pairs %s with no string", code) } actions[code] = action } diff --git a/hack/errcodes/main_test.go b/hack/errcodes/main_test.go index b48c0ef..219a21a 100644 --- a/hack/errcodes/main_test.go +++ b/hack/errcodes/main_test.go @@ -7,8 +7,14 @@ import ( "testing" ) -// spinSrc is errcode.go as spin writes it: the codes, then errorActions. -const spinSrc = `package cmd +// spinSrc is spin's cmd/cli/cmd as it writes the two: the codes in errcode.go, and failureKinds, +// which pairs each with its action and exit status, in exitcodes.go. +var spinSrc = map[string][]byte{ + "errcode.go": []byte(errcodeSrc), + "exitcodes.go": []byte(exitcodesSrc), +} + +const errcodeSrc = `package cmd type errorCode string @@ -20,14 +26,25 @@ const ( ) const muxPersist = "10m" +` -var errorActions = map[errorCode]string{ - codeNotSignedIn: "login", - codeKeyNotEnrolled: "add_key", - codeInternal: "details", +const exitcodesSrc = `package cmd + +var failureKinds = []failureKind{ + {codeInternal, "details", exitFailed}, + {codeNotSignedIn, "login", exitNotAllowed}, + {codeKeyNotEnrolled, "add_key", exitNotAllowed}, } ` +// withExitcodes is spinSrc with exitcodes.go's text replaced, old by new. +func withExitcodes(old, new string) map[string][]byte { + return map[string][]byte{ + "errcode.go": []byte(errcodeSrc), + "exitcodes.go": []byte(strings.Replace(exitcodesSrc, old, new, 1)), + } +} + const contractSrc = `export type Action = "login" | "add_key" | "details" export const ACTION_OF = { @@ -38,7 +55,7 @@ export const ACTION_OF = { ` func TestSpinActions(t *testing.T) { - got, err := spinActions([]byte(spinSrc)) + got, err := spinActions(spinSrc) if err != nil { t.Fatal(err) } @@ -102,7 +119,7 @@ func TestDiff(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - spin, err := spinActions([]byte(spinSrc)) + spin, err := spinActions(spinSrc) if err != nil { t.Fatal(err) } @@ -119,26 +136,57 @@ func TestDiff(t *testing.T) { } 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"}, + for _, tc := range []struct { + name string + spin map[string][]byte + contract string + want string + }{ + {"no Go file", map[string][]byte{}, contractSrc, "no Go file"}, + {"no table in spin", map[string][]byte{"errcode.go": []byte(errcodeSrc)}, contractSrc, "no failureKinds"}, + {"a code that is no constant", withExitcodes(`{codeInternal, "details"`, `{"internal", "details"`), contractSrc, "no constant"}, + {"a row that is no row", withExitcodes(`{codeInternal, "details", exitFailed},`, `internalKind,`), contractSrc, "no {code"}, {"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) + for name, src := range tc.spin { + if err := os.WriteFile(filepath.Join(dir, name), src, 0o600); err != nil { + t.Fatal(err) + } } + contract := filepath.Join(t.TempDir(), "contract.ts") if err := os.WriteFile(contract, []byte(tc.contract), 0o600); err != nil { t.Fatal(err) } - err := check(spin, contract) + err := check(dir, contract) if err == nil || !strings.Contains(err.Error(), tc.want) { t.Fatalf("got %v, want an error holding %q", err, tc.want) } }) } } + +// A test file of spin's is not its table: a fixture there names codes spin does not write. +func TestTestFilesAreNotRead(t *testing.T) { + dir := t.TempDir() + files := map[string]string{ + "errcode.go": errcodeSrc, + "exitcodes.go": exitcodesSrc, + "exitcodes_test.go": "package cmd\n\nvar failureKinds = []failureKind{{codeGone, \"details\", exitFailed}}\n", + } + for name, src := range files { + if err := os.WriteFile(filepath.Join(dir, name), []byte(src), 0o600); err != nil { + t.Fatal(err) + } + } + contract := filepath.Join(t.TempDir(), "contract.ts") + if err := os.WriteFile(contract, []byte(contractSrc), 0o600); err != nil { + t.Fatal(err) + } + if err := check(dir, contract); err != nil { + t.Fatal(err) + } +} diff --git a/src/auth/provider.ts b/src/auth/provider.ts index a551e4b..2029e7b 100644 --- a/src/auth/provider.ts +++ b/src/auth/provider.ts @@ -28,7 +28,7 @@ export class SpinboxAuthProvider implements vscode.AuthenticationProvider, vscod // installation unreachable) rejects, for the caller to show. async getSessions(): Promise { const v = await this.cli.version() - this.known = v.signed_in ? [session(v, v.user)] : [] + this.known = v.signedIn ? [session(v, v.user)] : [] return this.known } @@ -91,8 +91,8 @@ export class SpinboxAuthProvider implements vscode.AuthenticationProvider, vscod token.onCancellationRequested(() => abort.abort()) return this.cli.login( (start) => { - progress.report({ message: `enter ${start.user_code} on the page that opened` }) - void vscode.env.openExternal(vscode.Uri.parse(start.verification_url)) + progress.report({ message: `enter ${start.userCode} on the page that opened` }) + void vscode.env.openExternal(vscode.Uri.parse(start.verificationUrl)) }, { signal: abort.signal }, ) diff --git a/src/cli/client.ts b/src/cli/client.ts index 9c599d3..a232856 100644 --- a/src/cli/client.ts +++ b/src/cli/client.ts @@ -62,13 +62,13 @@ export interface CodeOptions extends RunOptions { // Hears each step of a server the installation prepares for this VS Code, as it begins. onPreparing?: (preparing: CodePreparing["preparing"]) => void // Hears that this computer's key waits for the person's passkey, on the page spin opened. - onConfirmingKey?: (confirming: CodeConfirmingKey["confirming_key"]) => void + onConfirmingKey?: (confirming: CodeConfirmingKey["confirmingKey"]) => void } // CliError is a command's failure as the CLI reported it: the envelope it wrote on stdout. export class CliError extends Error { readonly envelope: ErrorEnvelope - // The process's exit status: 1 for an envelope the CLI wrote, otherwise what it exited with, and + // The process's exit status, which names the failure's kind for an envelope the CLI wrote, and // -1 when it was killed for taking too long. readonly exitCode: number // The traceparent the command ran with, which names the trace its failure is found by. @@ -166,7 +166,7 @@ export class ProcessSpinCli implements SpinCli { } const r = await this.exec(args, opts, this.timeouts.login, (start, extend) => { if (isLoginStart(start)) { - extend(start.expires_in * 1000 + LOGIN_GRACE_MS) + extend(start.expiresIn * 1000 + LOGIN_GRACE_MS) onStart(start) } }) @@ -216,7 +216,7 @@ export class ProcessSpinCli implements SpinCli { } else if (isCodeConfirmingKey(p)) { // As long as spin waits for the person's passkey: its own wait ends sooner. extend(CONFIRMING_KEY_GRACE_MS) - opts.onConfirmingKey?.(p.confirming_key) + opts.onConfirmingKey?.(p.confirmingKey) } }) const [only, ...rest] = r.docs.filter((v) => !isCodePreparing(v) && !isCodeConfirmingKey(v)) @@ -415,13 +415,13 @@ function isObject(v: unknown): v is Record { function isLoginStart(v: unknown): v is LoginStart { return ( isObject(v) && - typeof v.verification_url === "string" && - typeof v.user_code === "string" && - typeof v.expires_in === "number" + typeof v.verificationUrl === "string" && + typeof v.userCode === "string" && + typeof v.expiresIn === "number" ) } // What a person is told while spin waits for their passkey to add this computer's key. -export function confirmingKeyMessage(c: CodeConfirmingKey["confirming_key"]): string { +export function confirmingKeyMessage(c: CodeConfirmingKey["confirmingKey"]): string { return `Confirm with your passkey, in the browser page spin opened, that ${c.name} connects to your workspaces` } diff --git a/src/cli/contract.ts b/src/cli/contract.ts index ffda334..a1ff1e2 100644 --- a/src/cli/contract.ts +++ b/src/cli/contract.ts @@ -1,10 +1,12 @@ -// The contract between this extension and the spin CLI, spin-stack/spin#833: every command is run -// with `-o json`, a success is one JSON object on stdout with exit 0 (`spin login --no-browser` -// 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. +// The contract between this extension and the spin CLI, spin-stack/spin#833 and #1605: every +// command is run with `-o json`, every key is camelCase, a success is one JSON object on stdout with +// exit 0 (`spin login --no-browser` and `spin code` write JSON lines), and a failure is one +// ErrorEnvelope on stdout with a non-zero exit that names its kind (`spin help exit-codes`). 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 errorActions in its -// cmd/cli/cmd/errcode.go, which `task contract:spin` (hack/errcodes) holds ACTION_OF to at the +// Each code, and the one action the CLI pairs with it. The CLI's list is failureKinds in its +// cmd/cli/cmd/exitcodes.go, which `task contract:spin` (hack/errcodes) holds ACTION_OF to at the // release versions.yaml pins. export type ErrorCode = | "cli_outdated" @@ -21,6 +23,17 @@ export type ErrorCode = // 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" + // The command line is not one spin takes: the extension's own mistake. + | "usage" + | "invalid" + | "not_found" + | "already_exists" + | "permission_denied" + // A command that asks to be confirmed, which none the extension runs does. + | "not_confirmed" + | "refused" + | "unavailable" + | "timed_out" | "internal" export type Action = @@ -31,8 +44,10 @@ export type Action = | "add_key" | "retry" | "details" + | "help" + | "confirm" -// The table in #833, as a type and as a value: a code missing from either fails typecheck. +// The table, as a type and as a value: a code missing from either fails typecheck. export const ACTION_OF = { cli_outdated: "update", not_signed_in: "login", @@ -43,6 +58,15 @@ export const ACTION_OF = { unreachable: "retry", no_extension_release: "details", no_vscode_server: "details", + usage: "help", + invalid: "details", + not_found: "details", + already_exists: "details", + permission_denied: "details", + not_confirmed: "confirm", + refused: "details", + unavailable: "retry", + timed_out: "retry", internal: "details", } as const satisfies Record @@ -55,7 +79,7 @@ export interface ErrorEnvelope { message: string // The release the installation runs, with cli_outdated. release?: string - workspace_id?: string + workspaceId?: string // 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 @@ -74,17 +98,17 @@ export interface VersionResult { cli: string profile: string endpoint: string - signed_in: boolean + signedIn: boolean installation?: string user?: User } // `spin login --no-browser -o json`, first line: written before it waits. export interface LoginStart { - verification_url: string - user_code: string + verificationUrl: string + userCode: string // Seconds. - expires_in: number + expiresIn: number } // `spin login --no-browser -o json`, second line: the login completed. @@ -102,28 +126,28 @@ export type ServerSource = "carried" | "downloaded" | "missing" // opened. export interface CodePreparing { preparing: { - vscode_version: string - vscode_commit: string + vscodeVersion: string + vscodeCommit: string step: string } } export interface CodeResult { - workspace_id: string + workspaceId: string host: string // vscode-remote://ssh-remote+ - folder_uri: string + folderUri: string server: ServerSource // Why the installation did not give the workspace this VS Code's server - its terms not // accepted, a publish that failed - where VS Code then downloads its own into the workspace. - not_given?: string + notGiven?: string } // The line spin code writes while this computer's key waits to be added to the person's account: // the page it opened, where their passkey confirms it. A first connection from a computer - VS // Code's, before anyone ran spin there - waits on this, not on an error. export interface CodeConfirmingKey { - confirming_key: { + confirmingKey: { url: string fingerprint: string name: string @@ -131,10 +155,10 @@ export interface CodeConfirmingKey { } export function isCodeConfirmingKey(v: unknown): v is CodeConfirmingKey { - if (typeof v !== "object" || v === null || !("confirming_key" in v)) { + if (typeof v !== "object" || v === null || !("confirmingKey" in v)) { return false } - const c = (v as { confirming_key: unknown }).confirming_key + const c = (v as { confirmingKey: unknown }).confirmingKey return typeof c === "object" && c !== null && typeof (c as { url?: unknown }).url === "string" } diff --git a/src/errors/index.ts b/src/errors/index.ts index deeaa61..efb64b8 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -171,13 +171,22 @@ async function show(error: unknown, retry: Retry | undefined, updated: boolean): return case "no_capacity": case "unreachable": + case "unavailable": + case "timed_out": return offer(vscode.window.showErrorMessage, TEXT[e.code], BUTTON.retry, retry, () => again()) case "no_extension_release": return internal(e, traceId, TEXT.no_extension_release) + // The message is what was refused and what resolves it - an administrator's publish, more room, + // a permission - so it is shown whole, with what internal offers beside it. 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. - return internal(e, traceId, TEXT.no_vscode_server) + case "usage": + case "invalid": + case "not_found": + case "already_exists": + case "permission_denied": + case "not_confirmed": + case "refused": + return internal(e, traceId, TEXT[e.code]) case "internal": return internal(e, traceId) } @@ -196,6 +205,15 @@ export const TEXT = { 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.", + usage: "Spinbox ran the spin CLI in a way it does not take.", + invalid: "The installation did not take what Spinbox asked.", + not_found: "The installation does not have what Spinbox asked for.", + already_exists: "That name is taken.", + permission_denied: "You are not allowed to do that.", + not_confirmed: "spin asked for a confirmation Spinbox cannot give.", + refused: "The installation refused.", + unavailable: "Part of the installation is away right now. Try again in a moment.", + timed_out: "The installation took too long. Try again in a moment.", internal: "Spinbox hit an unexpected error.", } as const satisfies Record diff --git a/src/open/open.ts b/src/open/open.ts index 523f901..8d650b3 100644 --- a/src/open/open.ts +++ b/src/open/open.ts @@ -79,16 +79,16 @@ async function open( onConfirmingKey: (c) => report(confirmingKeyMessage(c)), onPreparing: (p) => report( - `Preparing VS Code ${p.vscode_version} for this installation (once): ${p.step}`, + `Preparing VS Code ${p.vscodeVersion} for this installation (once): ${p.step}`, ), }) // The resolver never downloads a server: it refuses, and says what to do, itself. - if (r.not_given !== undefined && !deps.spin) { + if (r.notGiven !== undefined && !deps.spin) { deps.ui.showWarning( - `VS Code downloads its own server into ${target.workspace} (about 220 MB): the installation could not prepare it. ${r.not_given}`, + `VS Code downloads its own server into ${target.workspace} (about 220 MB): the installation could not prepare it. ${r.notGiven}`, ) } - return r.folder_uri + return r.folderUri } catch (err) { if (signal.aborted) { return undefined diff --git a/src/remote/connect.ts b/src/remote/connect.ts index 3f71f6b..b2f1c6d 100644 --- a/src/remote/connect.ts +++ b/src/remote/connect.ts @@ -63,7 +63,7 @@ export async function prepareConnection( traceparent, onConfirmingKey: (c) => report(confirmingKeyMessage(c)), onPreparing: (p) => - report(`Preparing VS Code ${p.vscode_version} for this installation (once): ${p.step}`), + report(`Preparing VS Code ${p.vscodeVersion} for this installation (once): ${p.step}`), }) return true } catch (err) { diff --git a/src/remote/proxy.ts b/src/remote/proxy.ts index 59fb675..5d53195 100644 --- a/src/remote/proxy.ts +++ b/src/remote/proxy.ts @@ -7,7 +7,7 @@ import { type ErrorEnvelope, isErrorEnvelope } from "../cli/contract" // atomically. Spinbox reads it, says each phase, and shows a refusal with what resolves it, where // Remote-SSH would show only that ssh exited. -export const STATUS_VERSION = 1 +export const STATUS_VERSION = 2 export type ProxyPhase = "resolving" | "connecting" | "connected" | "refused" | "failed" @@ -20,21 +20,21 @@ export interface ProxyError { action: string message: string release?: string - workspace_id?: string + workspaceId?: string url?: string } export interface ProxyStatus { version: typeof STATUS_VERSION host: string - ssh_pid: number + sshPid: number phase: ProxyPhase // ssh reuses an open connection, and no proxy runs. shared?: boolean - workspace_id?: string + workspaceId?: string error?: ProxyError - started_at: string - updated_at: string + startedAt: string + updatedAt: string } export interface ProxyStatusSource { @@ -58,10 +58,10 @@ export function readProxyStatus(body: string): ProxyStatus | undefined { if ( s.version !== STATUS_VERSION || typeof s.host !== "string" || - typeof s.ssh_pid !== "number" || + typeof s.sshPid !== "number" || !PHASES.includes(s.phase as ProxyPhase) || - !isTime(s.started_at) || - !isTime(s.updated_at) || + !isTime(s.startedAt) || + !isTime(s.updatedAt) || (s.error !== undefined && !isProxyError(s.error)) ) { return undefined @@ -99,8 +99,8 @@ export function fileProxyStatus(dir: string, host: string, since: number): Proxy if ( s !== undefined && s.host === host && - Date.parse(s.started_at) >= since && - (newest === undefined || Date.parse(s.updated_at) > Date.parse(newest.updated_at)) + Date.parse(s.startedAt) >= since && + (newest === undefined || Date.parse(s.updatedAt) > Date.parse(newest.updatedAt)) ) { newest = s } diff --git a/test/cli/real-spin.test.ts b/test/cli/real-spin.test.ts index ef4befd..a99649f 100644 --- a/test/cli/real-spin.test.ts +++ b/test/cli/real-spin.test.ts @@ -50,28 +50,31 @@ describe("the pinned spin CLI", () => { await expect(cli().version()).resolves.toMatchObject({ cli: expect.stringMatching(/^v\d{8}\.\d{2}$/), profile: "default", - signed_in: false, + signedIn: false, }) }) it.each([ - ["workspace list", (c: ProcessSpinCli) => c.listWorkspaces(), "not_signed_in", "login"], + ["workspace list", (c: ProcessSpinCli) => c.listWorkspaces(), "not_signed_in", "login", 77], [ "code", (c: ProcessSpinCli) => c.code("my-ws", undefined, "a".repeat(40)), "not_signed_in", "login", + 77, ], [ "login, its endpoint unreachable", (c: ProcessSpinCli) => c.login(() => {}, { endpoint: "http://127.0.0.1:1" }), "unreachable", "retry", + 69, ], - ])("fails %s with its envelope", async (_, run, code, action) => { + ])("fails %s with its envelope and its kind's status", async (_, run, code, action, status) => { const err = await rejection(run(cli())) - expect(err.exitCode).toBe(1) - expect(err.envelope).toEqual({ + expect(err.exitCode).toBe(status) + // What else spin says (next, detail) is not the extension's to read. + expect(err.envelope).toMatchObject({ error: { code, action, message: expect.any(String) }, }) }) diff --git a/test/fake-spin/spin.cjs b/test/fake-spin/spin.cjs index b3d7e2d..ab20830 100755 --- a/test/fake-spin/spin.cjs +++ b/test/fake-spin/spin.cjs @@ -1,15 +1,15 @@ #!/usr/bin/env node -// A fake spin CLI that answers as the contract in spin-stack/spin#833 says the real one does, so +// A fake spin CLI that answers as the contract in spin-stack/spin#833 and #1605 says the real one does, so // the extension is tested against every answer and every error code without an installation. // // What it answers, per command (version, login, workspace list, code, or any other): // -// FAKE_SPIN_ERROR= every command fails with that code's envelope, exit 1 +// FAKE_SPIN_ERROR= every command fails with that code's envelope and exit status // FAKE_SPIN_SCENARIO= a JSON object keyed by command ("version", "workspace list", ..., // "*" for any): {"stdout": [, ...], "stderr": "", // "exit": , "delayMs": , "lineDelayMs": } // or {"error": "", "message", -// "action", "release", "workspace_id", "url", "delayMs"}. A command it does not name gets the default answer. +// "action", "release", "workspaceId", "url", "delayMs"}. A command it does not name gets the default answer. // FAKE_SPIN_LOGIN_DELAY_MS how long login waits between its two lines (default 0) // FAKE_SPIN_LOG= every invocation's arguments appended as one JSON line // @@ -23,17 +23,28 @@ const fs = require("node:fs") -const ACTION_OF = { - cli_outdated: "update", - not_signed_in: "login", - workspace_stopped: "start", - workspace_failed: "open_dashboard", - key_not_enrolled: "add_key", - no_capacity: "retry", - unreachable: "retry", - no_extension_release: "details", - no_vscode_server: "details", - internal: "details", +// Each code's action and the status spin exits with for it, as failureKinds in spin's +// cmd/cli/cmd/exitcodes.go pairs them (`spin help exit-codes`). +const KIND_OF = { + cli_outdated: ["update", 1], + not_signed_in: ["login", 77], + workspace_stopped: ["start", 1], + workspace_failed: ["open_dashboard", 1], + key_not_enrolled: ["add_key", 77], + no_capacity: ["retry", 75], + unreachable: ["retry", 69], + no_extension_release: ["details", 1], + no_vscode_server: ["details", 1], + usage: ["help", 64], + invalid: ["details", 65], + not_found: ["details", 66], + already_exists: ["details", 65], + permission_denied: ["details", 77], + not_confirmed: ["confirm", 77], + refused: ["details", 1], + unavailable: ["retry", 75], + timed_out: ["retry", 75], + internal: ["details", 1], } const USER = { id: "u-1", email: "dev@example.com", name: "Dev" } @@ -93,7 +104,7 @@ const DEFAULTS = { cli: "v20261105.01", profile: "default", endpoint: ENDPOINT, - signed_in: true, + signedIn: true, installation: "v20261105.01", user: USER, }, @@ -102,9 +113,9 @@ const DEFAULTS = { login: { stdout: [ { - verification_url: `${ENDPOINT}/device?code=ABCD-EFGH`, - user_code: "ABCD-EFGH", - expires_in: 600, + verificationUrl: `${ENDPOINT}/device?code=ABCD-EFGH`, + userCode: "ABCD-EFGH", + expiresIn: 600, }, { profile: "default", endpoint: ENDPOINT, user: USER }, ], @@ -113,9 +124,9 @@ const DEFAULTS = { code: { stdout: [ { - workspace_id: "ws-1", + workspaceId: "ws-1", host: "spin.my-ws", - folder_uri: "vscode-remote://ssh-remote+spin.my-ws/root", + folderUri: "vscode-remote://ssh-remote+spin.my-ws/root", server: "carried", }, ], @@ -154,12 +165,12 @@ function parse(argv) { } function envelope(code, extra) { - if (!Object.hasOwn(ACTION_OF, code)) { + if (!Object.hasOwn(KIND_OF, code)) { throw new Error(`fake spin: unknown error code ${code}`) } // A scenario may set any envelope field, the action among them to answer one that is wrong. const fields = {} - for (const k of ["message", "action", "release", "workspace_id", "url"]) { + for (const k of ["message", "action", "release", "workspaceId", "url"]) { if (extra && k in extra) { fields[k] = extra[k] } @@ -170,14 +181,14 @@ function envelope(code, extra) { error: { code, message: `fake ${code}`, - action: ACTION_OF[code], + action: KIND_OF[code][0], ...(code === "cli_outdated" ? { release: "v20261105.01" } : {}), ...(code === "key_not_enrolled" ? { url: `${ENDPOINT}/settings/keys` } : {}), ...fields, }, }, ], - exit: 1, + exit: KIND_OF[code][1], } } diff --git a/test/unit/auth.test.ts b/test/unit/auth.test.ts index b26fb8e..dee8428 100644 --- a/test/unit/auth.test.ts +++ b/test/unit/auth.test.ts @@ -177,7 +177,7 @@ describe("SpinboxAuthProvider sessions", () => { scenario({ version: { stdout: [ - { cli: "v1", profile: "default", endpoint: "https://app.spinbox.test", signed_in: false }, + { cli: "v1", profile: "default", endpoint: "https://app.spinbox.test", signedIn: false }, ], }, }) diff --git a/test/unit/cli-client.test.ts b/test/unit/cli-client.test.ts index b469f0b..e2a5568 100644 --- a/test/unit/cli-client.test.ts +++ b/test/unit/cli-client.test.ts @@ -67,7 +67,7 @@ describe("ProcessSpinCli answers", () => { const logFile = join(tmp(), "argv") vi.stubEnv("FAKE_SPIN_LOG", logFile) const { cli: c } = cli() - await expect(c.version()).resolves.toMatchObject({ signed_in: true, profile: "default" }) + await expect(c.version()).resolves.toMatchObject({ signedIn: true, profile: "default" }) await expect(c.listWorkspaces()).resolves.toEqual([expect.objectContaining({ id: "ws-1" })]) const commit = "a".repeat(40) await expect( @@ -115,7 +115,7 @@ describe("ProcessSpinCli answers", () => { it("hands login's first line over before the login completes", async () => { vi.stubEnv("FAKE_SPIN_LOGIN_DELAY_MS", "300") const seen: string[] = [] - const done = await cli().cli.login((start) => seen.push(`start ${start.user_code}`), { + const done = await cli().cli.login((start) => seen.push(`start ${start.userCode}`), { endpoint: "https://app.spinbox.test", }) seen.push(`done ${done.user.email}`) @@ -136,7 +136,7 @@ describe("ProcessSpinCli failures", () => { expect(e.code).toBe(code) expect(e.envelope.error.action).toBe(ACTION_OF[code]) expect(e.message).toBe(`fake ${code}`) - expect(e.exitCode).toBe(1) + expect(e.exitCode).toBeGreaterThan(0) } }) @@ -229,7 +229,7 @@ describe("ProcessSpinCli kills a hung spin", () => { const binary = join(tmp(), "spin") writeFileSync( binary, - `#!/bin/sh\nsleep 20 &\necho '{"cli":"v20261105.01","profile":"default","endpoint":"e","signed_in":true}'\n`, + `#!/bin/sh\nsleep 20 &\necho '{"cli":"v20261105.01","profile":"default","endpoint":"e","signedIn":true}'\n`, ) chmodSync(binary, 0o755) const started = Date.now() @@ -243,7 +243,7 @@ describe("ProcessSpinCli kills a hung spin", () => { // heard as it comes. The steps are not the answer: the result after them is. it("not while a server is being prepared and says so", async () => { const step = (s: string) => ({ - preparing: { vscode_version: "1.120.0", vscode_commit: "a".repeat(40), step: s }, + preparing: { vscodeVersion: "1.120.0", vscodeCommit: "a".repeat(40), step: s }, }) scenario({ code: { @@ -252,9 +252,9 @@ describe("ProcessSpinCli kills a hung spin", () => { step("downloading"), step("building"), { - workspace_id: "ws-1", + workspaceId: "ws-1", host: "spin.my-ws", - folder_uri: "vscode-remote://x", + folderUri: "vscode-remote://x", server: "carried", }, ], @@ -281,11 +281,11 @@ describe("ProcessSpinCli kills a hung spin", () => { code: { lineDelayMs: 1000, stdout: [ - { confirming_key: confirming }, + { confirmingKey: confirming }, { - workspace_id: "ws-1", + workspaceId: "ws-1", host: "spin.my-ws", - folder_uri: "vscode-remote://x", + folderUri: "vscode-remote://x", server: "carried", }, ], diff --git a/test/unit/contract.test.ts b/test/unit/contract.test.ts index cf37189..6fef8c2 100644 --- a/test/unit/contract.test.ts +++ b/test/unit/contract.test.ts @@ -6,14 +6,17 @@ import { ACTION_OF, ERROR_CODES, isErrorEnvelope } from "../../src/cli/contract" import { runFake } from "./fake-spin" describe("error envelopes", () => { - it.each(ERROR_CODES)("%s fails with exit 1, one envelope, and the table's action", (code) => { - const r = runFake(["workspace", "list", "-o", "json"], { FAKE_SPIN_ERROR: code }) - expect(r.exit).toBe(1) - expect(r.docs).toHaveLength(1) - const [env] = r.docs - expect(isErrorEnvelope(env)).toBe(true) - expect(env).toMatchObject({ error: { code, action: ACTION_OF[code] } }) - }) + it.each(ERROR_CODES)( + "%s fails with a failure's status, one envelope, and the table's action", + (code) => { + const r = runFake(["workspace", "list", "-o", "json"], { FAKE_SPIN_ERROR: code }) + expect(r.exit).toBeGreaterThan(0) + expect(r.docs).toHaveLength(1) + const [env] = r.docs + expect(isErrorEnvelope(env)).toBe(true) + expect(env).toMatchObject({ error: { code, action: ACTION_OF[code] } }) + }, + ) it("rejects what is not an envelope of the contract", () => { for (const v of [ @@ -33,10 +36,10 @@ describe("error envelopes", () => { describe("fake spin", () => { it("answers each command with the contract's shape", () => { expect(runFake(["version", "-o", "json"]).docs).toEqual([ - expect.objectContaining({ cli: expect.any(String), signed_in: true }), + expect.objectContaining({ cli: expect.any(String), signedIn: true }), ]) expect(runFake(["login", "--no-browser", "-o", "json"]).docs).toEqual([ - expect.objectContaining({ user_code: "ABCD-EFGH", expires_in: 600 }), + expect.objectContaining({ userCode: "ABCD-EFGH", expiresIn: 600 }), expect.objectContaining({ profile: "default", user: expect.any(Object) }), ]) expect(runFake(["workspace", "list", "-o", "json"]).docs).toEqual([ @@ -51,7 +54,7 @@ describe("fake spin", () => { it("writes documents the way the real CLI does", () => { expect(runFake(["version", "-o", "json"]).stdout).toMatch(/^\{\n {2}"cli": /) expect(runFake(["login", "--no-browser", "-o", "json"]).stdout.split("\n")).toEqual([ - expect.stringMatching(/^\{"verification_url":.*\}$/), + expect.stringMatching(/^\{"verificationUrl":.*\}$/), expect.stringMatching(/^\{"profile":.*\}$/), "", ]) @@ -68,7 +71,7 @@ describe("fake spin", () => { ) const env = { FAKE_SPIN_SCENARIO: scenario } const r = runFake(["code", "my-ws", "-o", "json"], env) - expect(r.exit).toBe(1) + expect(r.exit).toBe(77) expect(r.docs).toEqual([ { error: { diff --git a/test/unit/documents.test.ts b/test/unit/documents.test.ts index 12a666e..bd5dad2 100644 --- a/test/unit/documents.test.ts +++ b/test/unit/documents.test.ts @@ -27,7 +27,7 @@ describe("documents", () => { describe("JsonDocuments", () => { it("hands out each document once its last bracket arrives, however the text is cut", () => { - const text = line({ verification_url: "u", user_code: "c" }) + indented({ profile: "p" }) + const text = line({ verificationUrl: "u", userCode: "c" }) + indented({ profile: "p" }) for (let size = 1; size <= text.length; size++) { const d = new JsonDocuments() const seen: unknown[][] = [] @@ -35,7 +35,7 @@ describe("JsonDocuments", () => { seen.push(d.push(text.slice(i, i + size))) } expect(seen.flat().concat(d.end())).toEqual([ - { verification_url: "u", user_code: "c" }, + { verificationUrl: "u", userCode: "c" }, { profile: "p" }, ]) // The first document is out by the chunk that holds its closing bracket, before the second. diff --git a/test/unit/errors.test.ts b/test/unit/errors.test.ts index 34d8da5..bb58f90 100644 --- a/test/unit/errors.test.ts +++ b/test/unit/errors.test.ts @@ -187,6 +187,18 @@ const CASES: Case[] = [ did: (retry) => expect(retry).toHaveBeenCalledWith(undefined), again: true, }, + { + code: "unavailable", + text: TEXT.unavailable, + button: BUTTON.retry, + did: (retry) => expect(retry).toHaveBeenCalledWith(undefined), + }, + { + code: "timed_out", + text: TEXT.timed_out, + button: BUTTON.retry, + did: (retry) => expect(retry).toHaveBeenCalledWith(undefined), + }, { code: "no_extension_release", text: `${TEXT.no_extension_release} no_extension_release msg`, @@ -202,6 +214,49 @@ const CASES: Case[] = [ did: () => expect(output.show).toHaveBeenCalled(), again: false, }, + // What was refused is the CLI's message, shown whole, with what internal offers. + { + code: "usage", + text: `${TEXT.usage} usage msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, + { + code: "invalid", + text: `${TEXT.invalid} invalid msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, + { + code: "not_found", + text: `${TEXT.not_found} not_found msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, + { + code: "already_exists", + text: `${TEXT.already_exists} already_exists msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, + { + code: "permission_denied", + text: `${TEXT.permission_denied} permission_denied msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, + { + code: "not_confirmed", + text: `${TEXT.not_confirmed} not_confirmed msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, + { + code: "refused", + text: `${TEXT.refused} refused msg`, + button: BUTTON.details, + did: () => expect(output.show).toHaveBeenCalled(), + }, { code: "internal", text: `${TEXT.internal} internal msg`, diff --git a/test/unit/open.test.ts b/test/unit/open.test.ts index 2920681..8db63e0 100644 --- a/test/unit/open.test.ts +++ b/test/unit/open.test.ts @@ -122,7 +122,7 @@ describe("openWorkspace", () => { // prepares its server, and the notification says each step. it("says each step of a server being prepared, then opens the folder", async () => { const step = (s: string) => ({ - preparing: { vscode_version: "1.120.0", vscode_commit: COMMIT, step: s }, + preparing: { vscodeVersion: "1.120.0", vscodeCommit: COMMIT, step: s }, }) const { deps, seen } = setup({ FAKE_SPIN_SCENARIO: scenario({ @@ -131,9 +131,9 @@ describe("openWorkspace", () => { step("downloading"), step("building"), { - workspace_id: "ws-1", + workspaceId: "ws-1", host: "spin.my-ws", - folder_uri: "vscode-remote://ssh-remote+spin.my-ws/root", + folderUri: "vscode-remote://ssh-remote+spin.my-ws/root", server: "carried", }, ], @@ -159,11 +159,11 @@ describe("openWorkspace", () => { code: { stdout: [ { - workspace_id: "ws-1", + workspaceId: "ws-1", host: "spin.my-ws", - folder_uri: "vscode-remote://ssh-remote+spin.my-ws/root", + folderUri: "vscode-remote://ssh-remote+spin.my-ws/root", server: "missing", - not_given: why, + notGiven: why, }, ], }, @@ -206,11 +206,11 @@ describe("openWorkspace", () => { code: { stdout: [ { - workspace_id: "ws-1", + workspaceId: "ws-1", host: "spin.my-ws", - folder_uri: "vscode-remote://ssh-remote+spin.my-ws/root", + folderUri: "vscode-remote://ssh-remote+spin.my-ws/root", server: "missing", - not_given: "no server", + notGiven: "no server", }, ], }, @@ -230,9 +230,9 @@ describe("openWorkspace", () => { code: { stdout: [ { - workspace_id: "ws-1", + workspaceId: "ws-1", host: "devbox", - folder_uri: "vscode-remote://ssh-remote+devbox/root", + folderUri: "vscode-remote://ssh-remote+devbox/root", server: "carried", }, ], @@ -285,7 +285,7 @@ describe("openWorkspace", () => { }) it("shows nothing and opens nothing when the progress is cancelled", async () => { - const file = scenario({ code: { stdout: [{ folder_uri: "x" }], delayMs: 10_000 } }) + const file = scenario({ code: { stdout: [{ folderUri: "x" }], delayMs: 10_000 } }) const { deps, seen } = setup({ FAKE_SPIN_SCENARIO: file }, { cancel: true }) const started = Date.now() await openWorkspace(deps, { workspace: "ws-1" }) diff --git a/test/unit/proxy.test.ts b/test/unit/proxy.test.ts index 4b4fa21..ed8dc47 100644 --- a/test/unit/proxy.test.ts +++ b/test/unit/proxy.test.ts @@ -16,16 +16,16 @@ const HOST = "spin.my-ws" const T0 = Date.parse("2026-11-12T22:00:00Z") const at = (ms: number) => new Date(T0 + ms).toISOString() -// A status file as spin#1180 writes it, version 1: shared, workspace_id and error left out when -// they have no value. +// A status file as spin writes it since spin#1605, version 2: shared, workspaceId and error left +// out when they have no value. function status(phase: ProxyStatus["phase"], o: Partial = {}): ProxyStatus { return { - version: 1, + version: 2, host: HOST, - ssh_pid: 4242, + sshPid: 4242, phase, - started_at: at(0), - updated_at: at(1), + startedAt: at(0), + updatedAt: at(1), ...o, } } @@ -46,14 +46,14 @@ function fixture(...statuses: (ProxyStatus | undefined)[]): ProxyStatusSource { describe("readProxyStatus", () => { it("reads a refusal with the CLI's error envelope", () => { const body = JSON.stringify({ - version: 1, + version: 2, host: HOST, - ssh_pid: 4242, + sshPid: 4242, phase: "refused", - workspace_id: "ws-1", + workspaceId: "ws-1", error: KEY_NOT_ENROLLED, - started_at: "2026-11-12T22:00:00.123456789Z", - updated_at: "2026-11-12T22:00:01.5Z", + startedAt: "2026-11-12T22:00:00.123456789Z", + updatedAt: "2026-11-12T22:00:01.5Z", }) expect(readProxyStatus(body)?.error).toEqual(KEY_NOT_ENROLLED) }) @@ -65,12 +65,23 @@ describe("readProxyStatus", () => { }) it.each([ - ["another version", { ...status("connected"), version: 2 }], + // What a spin before spin#1605 left in the directory. + [ + "version 1", + { + version: 1, + host: HOST, + ssh_pid: 4242, + phase: "connected", + started_at: at(0), + updated_at: at(1), + }, + ], ["no version", { ...status("connected"), version: undefined }], ["an unknown phase", { ...status("connected"), phase: "maybe" }], ["no host", { ...status("connected"), host: undefined }], - ["no pid", { ...status("connected"), ssh_pid: "4242" }], - ["a time that is no time", { ...status("connected"), updated_at: "soon" }], + ["no pid", { ...status("connected"), sshPid: "4242" }], + ["a time that is no time", { ...status("connected"), updatedAt: "soon" }], ["an error that is no envelope", { ...status("refused"), error: { code: "x" } }], ])("is nothing for %s", (_what, v) => { expect(readProxyStatus(JSON.stringify(v))).toBeUndefined() @@ -93,21 +104,21 @@ describe("fileProxyStatus", () => { it("reads the window's host's connection, last updated, begun since the window began", async () => { const d = dir({ "100.json": status("failed", { - ssh_pid: 100, - started_at: at(-60_000), - updated_at: at(-59_000), + sshPid: 100, + startedAt: at(-60_000), + updatedAt: at(-59_000), }), - "200.json": status("connected", { ssh_pid: 200, host: "spin.other", updated_at: at(9_000) }), - "300.json": status("resolving", { ssh_pid: 300, updated_at: at(1_000) }), - "400.json": status("connecting", { ssh_pid: 400, updated_at: at(2_000) }), - "500.json": { ...status("connected", { ssh_pid: 500, updated_at: at(8_000) }), version: 2 }, + "200.json": status("connected", { sshPid: 200, host: "spin.other", updatedAt: at(9_000) }), + "300.json": status("resolving", { sshPid: 300, updatedAt: at(1_000) }), + "400.json": status("connecting", { sshPid: 400, updatedAt: at(2_000) }), + "500.json": { ...status("connected", { sshPid: 500, updatedAt: at(8_000) }), version: 3 }, "notes.txt": "not a status", }) - expect((await fileProxyStatus(d, HOST, T0).read())?.ssh_pid).toBe(400) + expect((await fileProxyStatus(d, HOST, T0).read())?.sshPid).toBe(400) }) it("is nothing before any connection of the host is written", async () => { - const d = dir({ "100.json": status("failed", { started_at: at(-1) }) }) + const d = dir({ "100.json": status("failed", { startedAt: at(-1) }) }) expect(await fileProxyStatus(d, HOST, T0).read()).toBeUndefined() }) diff --git a/test/unit/status.test.ts b/test/unit/status.test.ts index 4006939..282836c 100644 --- a/test/unit/status.test.ts +++ b/test/unit/status.test.ts @@ -229,7 +229,7 @@ describe("Resume and Reconnect", () => { vi.stubEnv("FAKE_SPIN_SCENARIO", join(dir, "slow.json")) writeFileSync( join(dir, "slow.json"), - JSON.stringify({ code: { stdout: [{ folder_uri: "x" }], delayMs: 10_000 } }), + JSON.stringify({ code: { stdout: [{ folderUri: "x" }], delayMs: 10_000 } }), ) vs.withProgress.mockImplementation(progress(true)) const started = Date.now() From 21f934750d6fa5eb28b374766430d22d043e5ab3 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Tue, 1 Dec 2026 16:27:14 -0300 Subject: [PATCH 2/3] errors: the new codes answer whether to run again, as #65's cases do #65 gave every showEnvelope case an again; the nine codes this branch adds arrived without one, and refused, the code the unknown-code case used, is now the contract's. unavailable and timed_out retry, so they answer true; the rest go through internal and answer false. Co-Authored-By: Claude Opus 5.5 --- test/unit/errors.test.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/unit/errors.test.ts b/test/unit/errors.test.ts index bb58f90..5264262 100644 --- a/test/unit/errors.test.ts +++ b/test/unit/errors.test.ts @@ -192,12 +192,14 @@ const CASES: Case[] = [ text: TEXT.unavailable, button: BUTTON.retry, did: (retry) => expect(retry).toHaveBeenCalledWith(undefined), + again: true, }, { code: "timed_out", text: TEXT.timed_out, button: BUTTON.retry, did: (retry) => expect(retry).toHaveBeenCalledWith(undefined), + again: true, }, { code: "no_extension_release", @@ -220,42 +222,49 @@ const CASES: Case[] = [ text: `${TEXT.usage} usage msg`, button: BUTTON.details, did: () => expect(output.show).toHaveBeenCalled(), + again: false, }, { code: "invalid", text: `${TEXT.invalid} invalid msg`, button: BUTTON.details, did: () => expect(output.show).toHaveBeenCalled(), + again: false, }, { code: "not_found", text: `${TEXT.not_found} not_found msg`, button: BUTTON.details, did: () => expect(output.show).toHaveBeenCalled(), + again: false, }, { code: "already_exists", text: `${TEXT.already_exists} already_exists msg`, button: BUTTON.details, did: () => expect(output.show).toHaveBeenCalled(), + again: false, }, { code: "permission_denied", text: `${TEXT.permission_denied} permission_denied msg`, button: BUTTON.details, did: () => expect(output.show).toHaveBeenCalled(), + again: false, }, { code: "not_confirmed", text: `${TEXT.not_confirmed} not_confirmed msg`, button: BUTTON.details, did: () => expect(output.show).toHaveBeenCalled(), + again: false, }, { code: "refused", text: `${TEXT.refused} refused msg`, button: BUTTON.details, did: () => expect(output.show).toHaveBeenCalled(), + again: false, }, { code: "internal", @@ -547,7 +556,7 @@ describe("showEnvelope", () => { it("an envelope of a code the contract does not have is internal, with its message", async () => { click(BUTTON.retry) const answer = await showEnvelope({ - error: { code: "refused", action: "retry", message: "The installation said no." }, + error: { code: "quota_exceeded", action: "retry", message: "The installation said no." }, }) expect(answer).toBe(false) expect(shown()).toEqual({ From c2a881e01b7047afd09ae5e3e38c701ba024965a Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Tue, 1 Dec 2026 16:27:14 -0300 Subject: [PATCH 3/3] spin: v20261201.01, the first release whose -o json the contract reads The Bump spin workflow checks main's contract before it proposes, and main's contract is the old one, so no bump past spin#1828 could pass (run 46724498387: no errorActions). The pin moves with the contract that reads it, and package.json to the next patch so the merge releases it, as spin:propose would. Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- versions.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bb7b29b..14e77e0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "spinbox", "displayName": "Spinbox", "description": "Open Spinbox workspaces in VS Code over Remote-SSH, through the spin CLI.", - "version": "0.0.13", + "version": "0.0.14", "publisher": "spin-stack", "icon": "images/icon.png", "galleryBanner": { diff --git a/versions.yaml b/versions.yaml index 5abdd0e..e7262bf 100644 --- a/versions.yaml +++ b/versions.yaml @@ -5,8 +5,8 @@ - name: spin kind: git source: https://github.com/spin-stack/spin - version: v20261125.01 - pin: 40ba7e572a0041719cba3d5c5eae8ae1563a3817 + version: v20261201.01 + pin: 81001f84c090cfac27bd495f5f654a5c4438f2b0 track: github-release bump: task spin:bump note: >-