Skip to content

Commit e38a6a1

Browse files
sahrizviclaude
andcommitted
fix(workspace): identity renders unknown without the resolver when no complete account is configured
Nothing can verify a link without a credential, and the resolver's looser credential read would otherwise reach the network from that path with no memo, no single-flight and a synchronous git probe. Test asserts the resolver is not called. Also: the shell child-env test now exercises the default `process.env` base the production call site relies on. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent 4d27692 commit e38a6a1

3 files changed

Lines changed: 39 additions & 21 deletions

File tree

‎packages/opencode/src/altimate/workspace/identity.ts‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,11 @@ export async function systemSection(): Promise<string> {
350350
t.unref?.()
351351
timers.push(t)
352352
})
353-
// No complete account to memoise under. The resolver is still behind the deadline:
354-
// its own credential read is looser than `accountScope` (a file with an empty key
355-
// still names a tenant and host), so it can reach the network from here.
356-
if (!scope) {
357-
try {
358-
return render(
359-
await Promise.race([
360-
identityInternals.resolveBindingOutcome(directory),
361-
after(RESOLVE_DEADLINE_MS, () => ({ status: "unknown" })),
362-
]),
363-
)
364-
} finally {
365-
for (const t of timers) clearTimeout(t)
366-
}
367-
}
353+
// No complete account: nothing can verify a link, and the resolver's own credential
354+
// read is looser (a file with an empty key still names a tenant and host, and would
355+
// reach the network from here with no memo, no single-flight and a synchronous
356+
// `git remote` probe). Say so and do not invoke it.
357+
if (!scope) return render({ status: "unknown" })
368358
const key = keyFor(scope, directory)
369359
const hit = memo.get(key)
370360
if (fresh(hit)) return render(hit!.outcome)

‎packages/opencode/test/altimate/workspace/identity-section.test.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,21 +732,28 @@ describe("systemSection", () => {
732732
}
733733
})
734734

735-
test("a credentials file with an empty key still keeps the resolver behind the deadline", async () => {
736-
// `accountScope` refuses the empty key (nothing to memoise under), but the resolver's
737-
// own credential read still names a tenant and host and can reach the network — so
738-
// the no-scope path must be raced against the deadline too, or a hung server stalls
739-
// prompt assembly for the request timeout.
735+
test("a credentials file with an empty key renders unknown without invoking the resolver", async () => {
736+
// `accountScope` refuses the empty key, and nothing can verify a link without one —
737+
// so the resolver (whose own credential read still names a tenant and host, and
738+
// would reach the network with no memo or single-flight) is not called at all.
740739
const original = (AltimateApi as unknown as { getCredentials: () => Promise<Creds> }).getCredentials
741740
;(AltimateApi as unknown as { getCredentials: () => Promise<Creds> }).getCredentials = async () =>
742741
({ altimateInstanceName: "acme", altimateUrl: "https://api.example.com", altimateApiKey: "" }) as Creds
743742
globalThis.fetch = (() => new Promise(() => {})) as unknown as typeof fetch
743+
const realResolve = identityInternals.resolveBindingOutcome
744+
let resolves = 0
745+
identityInternals.resolveBindingOutcome = async (dir) => {
746+
resolves++
747+
return realResolve(dir)
748+
}
744749
try {
745750
const started = Date.now()
746751
const out = await inProject(systemSection)
747-
expect(Date.now() - started).toBeLessThan(RESOLVE_DEADLINE_MS + 500)
752+
expect(Date.now() - started).toBeLessThan(500)
748753
expect(out).toContain("could not be verified")
754+
expect(resolves).toBe(0)
749755
} finally {
756+
identityInternals.resolveBindingOutcome = realResolve
750757
;(AltimateApi as unknown as { getCredentials: () => Promise<Creds> }).getCredentials = original
751758
}
752759
})

‎packages/opencode/test/cli/run/run-mode.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ describe("host markers do not leak into child processes", () => {
195195
expect(env.PATH).toBe("/bin")
196196
})
197197

198+
test("with no explicit base, the child environment is the real process environment, stripped", async () => {
199+
// The only production call site passes `extra` alone and relies on the default base.
200+
const { shellChildEnv } = await import("../../../src/tool/shell")
201+
const savedRun = process.env.ALTIMATE_RUN_MODE
202+
const savedSentinel = process.env.ALTIMATE_TEST_SENTINEL_937
203+
process.env.ALTIMATE_RUN_MODE = "1"
204+
process.env.ALTIMATE_TEST_SENTINEL_937 = "present"
205+
try {
206+
const env = shellChildEnv({ FROM_PLUGIN: "1" })
207+
expect(env.ALTIMATE_TEST_SENTINEL_937).toBe("present") // process.env came through
208+
expect(env.ALTIMATE_RUN_MODE).toBeUndefined() // and was stripped
209+
expect(env.FROM_PLUGIN).toBe("1")
210+
expect(env.PATH).toBe(process.env.PATH)
211+
} finally {
212+
if (savedRun === undefined) delete process.env.ALTIMATE_RUN_MODE
213+
else process.env.ALTIMATE_RUN_MODE = savedRun
214+
if (savedSentinel === undefined) delete process.env.ALTIMATE_TEST_SENTINEL_937
215+
else process.env.ALTIMATE_TEST_SENTINEL_937 = savedSentinel
216+
}
217+
})
218+
198219
test("on Windows every spelling of a marker is stripped; on POSIX only the exact name", () => {
199220
const env = { altimate_code_serve: "1", Altimate_Pinned_Workspace_Id: "7", ALTIMATE_CODE_SERVE: "1", PATH: "x" }
200221
const win = stripHostMarkers({ ...env }, "win32")

0 commit comments

Comments
 (0)