{"version":140,"agent":"codex-capacity-chair","message":"Avoid line projection for file attribute queries","time":1791845368566,"timeIso":"2026-10-12T22:49:28.566Z","changes":2,"change":1284,"files":["src/engine/test/attribute-projection.test.ts","src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/test/attribute-projection.test.ts","added":57,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/attribute-projection.test.ts\n@@ -0,0 +1,57 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { Graph } from \"../graph.ts\";\n+import { CachedStateStorage, StableOverlaySet } from \"../state-source.ts\";\n+import { View } from \"../view.ts\";\n+import { Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"attribute queries and explicit file existence do not traverse line history\", (t) => {\n+\tconst repo = Repo.init({ \"file.txt\": \"one\\ntwo\\n\" });\n+\tconst base = new Set(repo.shared);\n+\trepo.edit({\n+\t\tattrs: [\n+\t\t\t{ file: \"file.txt\", name: \"exec\", value: \"1\" },\n+\t\t\t{ file: \"empty.txt\", name: \"exists\", value: \"1\" },\n+\t\t\t{ file: \"link.txt\", name: \"link\", value: \"target\" },\n+\t\t],\n+\t});\n+\tconst first = new Set(repo.shared);\n+\trepo.edit({\n+\t\tattrs: [\n+\t\t\t{ file: \"file.txt\", name: \"exec\", value: null },\n+\t\t\t{ file: \"empty.txt\", name: \"exists\", value: null },\n+\t\t\t{ file: \"link.txt\", name: \"link\", value: null },\n+\t\t],\n+\t});\n+\tconst source = new SqlState();\n+\ttry {\n+\t\tconst disk = new Graph({ storage: new CachedStateStorage(source) });\n+\t\tfor (const id of repo.shared) disk.add(repo.graph.atom(id));\n+\t\tfor (const graph of [repo.graph, new Graph({ storage: new CachedStateStorage(source) })]) {\n+\t\t\tfor (const set of [base, first, repo.shared]) {\n+\t\t\t\tconst view = new View(graph, new StableOverlaySet(set));\n+\t\t\t\tconst before = view.weight();\n+\t\t\t\tconst guard = t.mock.method(graph, \"startCodeOf\", () => {\n+\t\t\t\t\tthrow new Error(\"line traversal forbidden\");\n+\t\t\t\t});\n+\t\t\t\tassert.equal(view.attrs(\"file.txt\").exec, set === first);\n+\t\t\t\tassert.equal(view.attrs(\"empty.txt\").exists, set === first);\n+\t\t\t\tassert.equal(view.attrs(\"link.txt\").link, set === first ? \"target\" : null);\n+\t\t\t\tassert.deepEqual(view.attrs(\"missing.txt\"), { exists: false, exec: false, link: null, blob: null });\n+\t\t\t\tif (set === first) {\n+\t\t\t\t\tassert.equal(view.hasFile(\"empty.txt\"), true);\n+\t\t\t\t\tassert.equal(view.hasFile(\"link.txt\"), true);\n+\t\t\t\t}\n+\t\t\t\tassert.equal(view.weight(), before);\n+\t\t\t\tguard.mock.restore();\n+\t\t\t\tassert.equal(view.hasFile(\"file.txt\"), true, \"text-only files retain line fallback\");\n+\t\t\t\tassert.equal(view.hasFile(\"missing.txt\"), false);\n+\t\t\t\tassert.equal(view.hasFile(\"empty.txt\"), set === first);\n+\t\t\t\tassert.equal(view.text(\"file.txt\"), \"one\\ntwo\\n\");\n+\t\t\t}\n+\t\t}\n+\t} finally {\n+\t\tsource.db.close();\n+\t}\n+});"},{"path":"src/engine/view.ts","added":16,"removed":10,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -420,7 +420,7 @@\n \t\treturn this.#layoutResolved(path, complete);\n \t}\n \n-\t#layoutResolved(path: string, complete: boolean, nodes?: Iterable<number>): FileState {\n+\t#attributes(path: string): FileAttrs {\n \t\tconst graph = this.graph;\n \t\t// For each attribute, the highest-priority setter in the set wins.\n \t\tconst setters = new Map<string, { id: AtomId; value: string | null }>();\n@@ -433,6 +433,17 @@\n \t\t\t}\n \t\t}\n \n+\t\treturn {\n+\t\t\texists: setters.get(\"exists\")?.value === \"1\",\n+\t\t\texec: setters.get(\"exec\")?.value === \"1\",\n+\t\t\tlink: setters.get(\"link\")?.value ?? null,\n+\t\t\tblob: setters.get(\"blob\")?.value ?? null,\n+\t\t};\n+\t}\n+\n+\t#layoutResolved(path: string, complete: boolean, nodes?: Iterable<number>): FileState {\n+\t\tconst graph = this.graph;\n+\t\tconst attrs = this.#attributes(path);\n \t\tconst seq: number[] = [];\n \t\tconst vis: number[] = [];\n \t\tconst deletedBy = new Map<number, readonly number[]>();\n@@ -453,12 +464,7 @@\n \t\t\t} else vis.push(n);\n \t\t\tif (complete) seq.push(n);\n \t\t}\n-\t\tconst attrs: FileAttrs = {\n-\t\t\texists: setters.get(\"exists\")?.value === \"1\",\n-\t\t\texec: setters.get(\"exec\")?.value === \"1\",\n-\t\t\tlink: setters.get(\"link\")?.value ?? null,\n-\t\t\tblob: setters.get(\"blob\")?.value ?? null,\n-\t\t};\n+\n \t\treturn { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };\n \t}\n \n@@ -496,13 +502,13 @@\n \n \t/** Whether the file exists in this projection (has a visible line). */\n \thasFile(path: string): boolean {\n-\t\tconst f = this.#file(path);\n-\t\treturn f.vis.length > 0 || f.attrs.exists || f.attrs.link !== null || f.attrs.blob !== null;\n+\t\tconst attrs = this.attrs(path);\n+\t\treturn attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0;\n \t}\n \n \t/** A file's attributes: kept while empty, executable, a link's target. */\n \tattrs(path: string): FileAttrs {\n-\t\treturn this.#file(path).attrs;\n+\t\treturn this.#files.get(path)?.attrs ?? this.#attributes(path);\n \t}\n \n \t/** The projected text of a file (\"\" if it has no visible lines). */"}],"ci":null}