fix(core): ignore a corrupt cached project id

This commit is contained in:
Dan Smolsky
2026-11-07 06:45:46 -05:00
Unverified
parent c72ce6cf82
commit a60ad169ea
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -309,7 +309,7 @@ const layer = Layer.effect(
const cached = Effect.fnUntraced(function* (dir: string) {
return yield* fs.readFileString(path.join(dir, "opencode")).pipe(
Effect.map((value) => value.trim()),
Effect.map((value) => (value ? ID.make(value) : undefined)),
Effect.map((value) => (value && !/[\u0000-\u001f\u007f]/.test(value) ? ID.make(value) : undefined)),
Effect.orElseSucceed(() => undefined),
)
})
+14
View File
@@ -551,6 +551,20 @@ describe("Project.resolve", () => {
}),
)
it.live("ignores a cached id with control characters", () =>
Effect.gen(function* () {
const tmp = yield* tmpdirScoped()
yield* Effect.promise(() => initRepo(tmp.path, { commit: true }))
yield* Effect.promise(() => Bun.write(path.join(tmp.path, ".git", "opencode"), "\u0000".repeat(40)))
const project = yield* Project.Service
const result = yield* project.resolve(abs(tmp.path))
expect(result.previous).toBeUndefined()
expect(result.id).toBe(Project.ID.make(yield* Effect.promise(() => rootCommit(tmp.path))))
}),
)
it.live("does not write the cache while resolving", () =>
Effect.gen(function* () {
const tmp = yield* tmpdirScoped()