Skip to content
Merged
2 changes: 1 addition & 1 deletion src/lib/onboard/sandbox-provider-cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const TOLERATED_DETACH_OUTPUT_RE =

const MISSING_SANDBOX_OUTPUT_RE = /sandbox[^\n]{0,200}?(?:\bNotFound\b|\bnot\s+found\b)/i;

const ATTACHED_TO_SANDBOX_RE = /attached\s+to\s+sandbox\(\s*es?\s*\)?\s*:\s*([^"\n]+)/i;
const ATTACHED_TO_SANDBOX_RE = /attached\s+to(?:\s|│)+sandbox\(\s*es?\s*\)?\s*:\s*([^"\n]+)/i;

const MAX_WARNING_OUTPUT_CHARS = 500;

Expand Down
14 changes: 12 additions & 2 deletions test/sandbox-provider-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ describe("parseAttachedSandboxes", () => {
expect(parseAttachedSandboxes(output)).toEqual(["spark-nemo"]);
});

it("parses an OpenShell diagnostic wrapped with continuation markers", () => {
const output =
"Error: × code: 'The system is not in a state required for the operation's\n" +
"│ execution', message: \"provider 'compatible-endpoint' is attached to\n" +
'│ sandbox(es): e2e-diag"';
expect(parseAttachedSandboxes(output)).toEqual(["e2e-diag"]);
});

it("parses multiple sandbox names from the same diagnostic", () => {
const output = "provider 'x' is attached to sandbox(es): alpha, beta, gamma";
expect(parseAttachedSandboxes(output)).toEqual(["alpha", "beta", "gamma"]);
Expand Down Expand Up @@ -382,7 +390,7 @@ describe("deleteProviderWithRecovery", () => {
expect(result.recoveryFailures).toEqual([]);
});

it("parses attached sandbox(es) and retries delete after force-detach", () => {
it("retries delete after force-detaching a sandbox from a wrapped diagnostic", () => {
let attempt = 0;
const calls: string[][] = [];
const runOpenshell = vi.fn((args: string[]) => {
Expand All @@ -394,7 +402,9 @@ describe("deleteProviderWithRecovery", () => {
status: 1,
stdout: "",
stderr:
"Error: status: FailedPrecondition, message: \"provider 'p' is attached to sandbox(es): orphan-one\"",
"Error: × code: 'The system is not in a state required for the operation's\n" +
"│ execution', message: \"provider 'p' is attached to\n" +
'│ sandbox(es): orphan-one"',
};
}
return { status: 0, stdout: "", stderr: "" };
Expand Down