|
1 | 1 | import assert from 'node:assert/strict'; |
| 2 | +import { execFileSync } from 'node:child_process'; |
2 | 3 | import { test } from 'node:test'; |
3 | 4 | import { resolveImportEdges } from './model.ts'; |
| 5 | +import { mergeBaseRatchets } from './ratchet-reference.ts'; |
| 6 | +import { readCommittedSources } from '../__tests__/committed-source-tree.ts'; |
4 | 7 | import { |
5 | 8 | checkSessionAuthorityOverlay, |
6 | 9 | handlerOwnedOverlay, |
@@ -165,6 +168,56 @@ test('the end-to-end measurement feeds the ratchet: a new handler importer is re |
165 | 168 | assert.equal(violations[0]!.file, 'packages/daemon/src/sessions/handlers/new.ts'); |
166 | 169 | }); |
167 | 170 |
|
| 171 | +test('the overlay classifies handler writes in both live handler roots, measured end to end', () => { |
| 172 | + // A write planted in each live layer folder must land in the ratcheted subset; the pre-fold |
| 173 | + // flat handlers/ spelling is dead in both trees (R10's retired-path guards own re-creation |
| 174 | + // there), so a write there stays out of scope even though the raw measurement sees it. |
| 175 | + const sources = { |
| 176 | + 'packages/daemon/src/core/session-state.ts': STATE_STUB, |
| 177 | + 'packages/daemon/src/core/session-store.ts': STORE_STUB, |
| 178 | + 'packages/daemon/src/sessions/handlers/session-runtime.ts': |
| 179 | + "import { SessionStore } from '../../core/session-store.ts';\n", |
| 180 | + 'packages/daemon/src/execution/handlers/snapshot-route.ts': |
| 181 | + "import type { SessionState } from '../../core/session-state.ts';\n", |
| 182 | + 'packages/daemon/src/handlers/legacy.ts': |
| 183 | + "import type { SessionState } from '../core/session-state.ts';\n", |
| 184 | + }; |
| 185 | + const measured = handlerOwnedOverlay(overlayOf(sources)); |
| 186 | + assert.deepEqual(measured, { |
| 187 | + shapeFiles: ['packages/daemon/src/execution/handlers/snapshot-route.ts'], |
| 188 | + authorityFiles: ['packages/daemon/src/sessions/handlers/session-runtime.ts'], |
| 189 | + }); |
| 190 | + // The raw overlay sees the stale spelling, so the exclusion above is the root filter's doing. |
| 191 | + assert.ok(overlayOf(sources).shapeFiles.includes('packages/daemon/src/handlers/legacy.ts')); |
| 192 | +}); |
| 193 | + |
| 194 | +test('the merge-base overlay arrives in head coordinates through the rename mapping', () => { |
| 195 | + // The merge-base tree declares SessionState under src/daemon/... and holds no layer folders. |
| 196 | + // mergeBaseRatchets canonicalizes every base path through renamedSince (the base's |
| 197 | + // src/daemon/handlers/*.ts pair with the head's layer-folder handlers/*.ts, and |
| 198 | + // session-store.ts pairs under core/), so the reference handler-owned set must already name |
| 199 | + // the live roots. This is what lets checkSessionAuthorityOverlay compare paths directly and |
| 200 | + // what makes the old flat handlers/ spellings in this rule dead weight. |
| 201 | + const repoRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], { |
| 202 | + encoding: 'utf8', |
| 203 | + }).trim(); |
| 204 | + const reference = mergeBaseRatchets(repoRoot); |
| 205 | + const scoped = handlerOwnedOverlay(reference.sessionAuthority); |
| 206 | + assert.ok(scoped.shapeFiles.length > 0 && scoped.authorityFiles.length > 0); |
| 207 | + for (const file of [...scoped.shapeFiles, ...scoped.authorityFiles]) { |
| 208 | + assert.match( |
| 209 | + file, |
| 210 | + /^packages\/daemon\/src\/(?:sessions|execution)\/handlers\//, |
| 211 | + `merge-base handler member left the live roots: ${file}`, |
| 212 | + ); |
| 213 | + } |
| 214 | + const baseSources = readCommittedSources(repoRoot, reference.ref).sources; |
| 215 | + assert.ok( |
| 216 | + [...baseSources.keys()].some((file) => file.startsWith('src/daemon/handlers/')), |
| 217 | + 'the merge-base tree is expected to hold the pre-layer-folder src/daemon/handlers/ root', |
| 218 | + ); |
| 219 | +}); |
| 220 | + |
168 | 221 | test('R75 catches a new handler shape edge expressed as an import type', () => { |
169 | 222 | const base = { |
170 | 223 | 'packages/daemon/src/core/session-state.ts': STATE_STUB, |
|
0 commit comments