diff --git a/docs/optimize/callable-end-to-end-v2-report.md b/docs/optimize/callable-end-to-end-v2-report.md new file mode 100644 index 000000000..c1bb7a821 --- /dev/null +++ b/docs/optimize/callable-end-to-end-v2-report.md @@ -0,0 +1,48 @@ +# Callable indexing: confirmed end-to-end improvement + +The retained change reduces complete indexing time by **5.78% on the repository workload** and **5.87% on held-out declarations**, compared with PR #3726 before the identity optimization. Both comparisons pass the predeclared 3% paired improvement threshold and all graph/cache correctness checks. The same candidate also improves on the pre-refactor control. + +## Change + +The existing identity-guard subprocess samples up to 16 distributed metadata requests. It uses synchronous filesystem reads when the sample completes within 8 ms, avoiding thread-pool overhead on fast storage; otherwise it retains concurrent asynchronous batches. Sampling stops when the budget is exhausted. All requests still run, results retain their original order, and file states, symlink targets, directory inventories and before/after mutation checks are preserved. The subprocess boundary and direct-validator fallback remain in place. + +This affects the subprocess path used for large guard sets on writable installations. It does not remove method-extractors: the original refactor shares pure declaration facts while each consumer keeps its graph/resolution responsibilities. + +## Complete indexing measurements + +Each cell is baseline → candidate, in seconds. Values are medians of three alternating pairs. A total is the median of each process's cold + warm + changed runs, so it need not equal the sum of the three column medians. + +| Workload | Baseline | Cold | Warm | One file changed | Total | Total reduction | +| ------------ | ------------ | --------------: | ------------: | ---------------: | --------------: | --------------: | +| Repository | Pre-refactor | 13.992 → 13.645 | 4.512 → 4.044 | 5.592 → 5.228 | 23.961 → 22.964 | 4.16% | +| Repository | Initial PR | 13.972 → 13.498 | 4.538 → 4.012 | 5.565 → 5.226 | 24.159 → 22.762 | 5.78% | +| Declarations | Pre-refactor | 9.821 → 9.103 | 2.620 → 2.331 | 3.530 → 3.203 | 15.987 → 14.624 | 8.52% | +| Declarations | Initial PR | 9.369 → 9.112 | 2.626 → 2.321 | 3.562 → 3.228 | 15.601 → 14.686 | 5.87% | + +Versus the initial PR, warm runs improve by 11.59% on the repository workload and 11.63% on held-out declarations. Changed-file runs improve by 6.09% and 9.39%, respectively. Cold medians are lower, but the paired cold result does not establish a consistent improvement above 3%. No required objective violates its 3% regression limit. + +Every repository pair improves total time by more than 4% versus the pre-refactor control and more than 5.6% versus the initial PR. Held-out pairs improve by more than 5.2% and 5.8%, respectively. Identical-runtime A/A total variation is −0.83% to +1.12% for the repository corpus and −2.38% to +0.60% for declarations. + +[Repository run](https://github.com/abhigyanpatwari/GitNexus/actions/runs/40271406528) and [held-out run](https://github.com/abhigyanpatwari/GitNexus/actions/runs/40272393865) both succeeded. [Machine-readable measurements](callable-end-to-end-v2-results.json) preserve all metric samples, correctness receipts, source identities, runner metadata and decisions. + +## Reproduction and measurement boundaries + +- Control: `f759753794fda8e399d670ef7f04b9d7473d6082`; initial PR: `b31dfb73c368f3d1254cfafb6eb6b2ed7453e221`. +- Candidate: the initial PR plus the [tested patch](https://github.com/abhigyanpatwari/GitNexus/blob/4b274ae0645d185b91ee1d1f94000d2ee3e634e2/docs/optimize/callable-end-to-end-experiment/candidate.patch). +- The [temporary experiment workflow](https://github.com/abhigyanpatwari/GitNexus/blob/58db59f0e2936757179bdb22575ba203e2319f5f/.github/workflows/callable-end-to-end.yml) builds all three revisions with the same installed dependencies, then runs the frozen benchmark serially on a dedicated Ubuntu runner with four CPUs and Node 22.23.3. It is kept on the experiment branch, outside the product PR. +- The benchmark uses one real parser worker, a 128 MiB database buffer pool, full graph persistence, and cold/warm/one-file-change scenarios. FTS and embeddings are disabled. Shared index storage is disabled. +- Every child gets a fresh private `XDG_RUNTIME_DIR`. Identity caches live outside `GITNEXUS_HOME`; isolating only the repository would leave rebuild-dependent cache asymmetry. The workload and measurement code were frozen before selection; the declaration holdout ran only after selection qualified. +- Across both runs, 108 complete analyses preserve structural graph hashes. Warm runs reparse zero files, and changed runs reparse exactly one. Community/process clustering output is excluded from structural hashes because it is nondeterministic. +- These are two fixed workloads, not a guarantee for every repository or filesystem. Earlier shared-host timings were inconclusive and are not the basis for this claim. + +## Validation and rejected alternatives + +Build, production/test typechecks, formatting and scoped ESLint pass. The final candidate passes 242 tests across 12 files, including the new I/O-route tests, identity invalidation/symlink tests, packaged-parser identity test, setup tests and native rename tests. The new tests exercise ordered results beyond a batch boundary, missing/invalid paths, symlinks, and directory mutation rejection on both I/O paths. + +An earlier full local suite reported 28,404 passes, 89 skips, six failures and a native-worker abort. Every failing file and the aborting file passed the 242-test follow-up with inherited `CODEX_HOME` removed from that test process and an already available compatible libstdc++. No package dependency changed. The full suite was not rerun locally; its earlier failure remains recorded. + +The parent-map/source-range experiment passed 219 focused tests but did not improve overall time and failed its warm-run gate; it was reverted. Leaf-operand fast paths passed 31 tests and reduced native field reads by 15.7%, but extraction time did not improve; they were also reverted. Neither parser experiment is included in the retained change. + +Impact analysis identifies identity validation as HIGH risk upstream of analysis/status/finalization. Review checked the real subprocess script, all probe modes, its callers and the direct fallback. Sequential review followed the repository's no-subagent mapping; no independent model review is claimed. The change preserves cache formats and validation checks and needs no migration. + +Graph change analysis was rerun after staging. It maps the runtime change but remains partial because the new test file is absent from the baseline index. The test is checked by its executed Vitest cases and direct call-site review; the empty graph caller count is not treated as an all-clear. diff --git a/docs/optimize/callable-end-to-end-v2-results.json b/docs/optimize/callable-end-to-end-v2-results.json new file mode 100644 index 000000000..f72b89359 --- /dev/null +++ b/docs/optimize/callable-end-to-end-v2-results.json @@ -0,0 +1,1175 @@ +{ + "revisions": { + "control": "f759753794fda8e399d670ef7f04b9d7473d6082", + "initial_pr": "b31dfb73c368f3d1254cfafb6eb6b2ed7453e221", + "candidate_patch_commit": "4b274ae0645d185b91ee1d1f94000d2ee3e634e2", + "candidate_patch_sha256": "52675a2de4896513a3eabc906cda95ee87af4b405f4b5b635f5aeee78d3ffcc4", + "candidate_source_sha256": "3e0ef70e08446780e47f92b9a3364094234b60b900064f8abcdebe53aed02912" + }, + "comparisons": { + "Repository": { + "run": "https://github.com/abhigyanpatwari/GitNexus/actions/runs/40271406528", + "environment": { + "corpus": "repository", + "harness_sha256": "e3a9d522a1fd7b0a93c4863bf8c3299f1f37127df12005142a9a81ff8417d029", + "cpus": [0, 1, 2, 3], + "node": "v22.23.3", + "identity_cache": "fresh private XDG_RUNTIME_DIR for every child on both sides" + }, + "comparisons": { + "aa": { + "snapshots": { + "reference": { + "metrics": { + "cold_ms": { + "aggregate": 14012.219796, + "samples": [14085.624297999999, 14012.219796, 13789.759022999999] + }, + "warm_ms": { + "aggregate": 4422.446205, + "samples": [4422.446205, 4482.817974, 4412.300960999999] + }, + "changed_ms": { + "aggregate": 5551.229650999998, + "samples": [5488.4052550000015, 5604.500476999998, 5551.229650999998] + }, + "total_ms": { + "aggregate": 23996.475758, + "samples": [23996.475758, 24099.538246999997, 23753.289634999994] + } + }, + "gates": { + "graph_parity": 1 + } + }, + "candidate": { + "metrics": { + "cold_ms": { + "aggregate": 13922.462496, + "samples": [13922.462496, 13886.752366, 14011.912793] + }, + "warm_ms": { + "aggregate": 4434.282054000001, + "samples": [4421.982065, 4449.050078999999, 4434.282054000001] + }, + "changed_ms": { + "aggregate": 5564.556627000002, + "samples": [5504.022850000001, 5564.556627000002, 5573.942568000002] + }, + "total_ms": { + "aggregate": 23900.359072, + "samples": [23848.467411, 23900.359072, 24020.137415000005] + } + }, + "gates": { + "graph_parity": 1 + } + } + }, + "graph_receipts": [ + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + } + ] + }, + "control": { + "snapshots": { + "reference": { + "metrics": { + "cold_ms": { + "aggregate": 13991.763434, + "samples": [13991.763434, 13805.25828, 14366.420702] + }, + "warm_ms": { + "aggregate": 4511.715841000001, + "samples": [4431.737887000001, 4511.715841000001, 4550.253875999999] + }, + "changed_ms": { + "aggregate": 5592.197659999998, + "samples": [5406.134773000002, 5643.626838, 5592.197659999998] + }, + "total_ms": { + "aggregate": 23960.600959000003, + "samples": [23829.636094, 23960.600959000003, 24508.872237999996] + } + }, + "gates": { + "graph_parity": 1 + } + }, + "candidate": { + "metrics": { + "cold_ms": { + "aggregate": 13644.659769, + "samples": [13644.659769, 13718.16581, 13622.536973] + }, + "warm_ms": { + "aggregate": 4043.813024000001, + "samples": [4013.4213339999988, 4043.813024000001, 4088.9500709999975] + }, + "changed_ms": { + "aggregate": 5227.569141, + "samples": [5199.405332000002, 5227.569141, 5252.548638] + }, + "total_ms": { + "aggregate": 22964.035681999998, + "samples": [22857.486435, 22989.547975, 22964.035681999998] + } + }, + "gates": { + "graph_parity": 1 + } + } + }, + "graph_receipts": [ + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + } + ] + }, + "initial": { + "snapshots": { + "reference": { + "metrics": { + "cold_ms": { + "aggregate": 13971.703595, + "samples": [14124.960014, 13888.564035, 13971.703595] + }, + "warm_ms": { + "aggregate": 4538.477369, + "samples": [4491.405017000001, 4655.3875530000005, 4538.477369] + }, + "changed_ms": { + "aggregate": 5565.317494999999, + "samples": [5565.317494999999, 5614.9098730000005, 5512.058400000002] + }, + "total_ms": { + "aggregate": 24158.861461, + "samples": [24181.682526, 24158.861461, 24022.239364] + } + }, + "gates": { + "graph_parity": 1 + } + }, + "candidate": { + "metrics": { + "cold_ms": { + "aggregate": 13498.288122, + "samples": [13498.288122, 13530.87846, 13485.260099000001] + }, + "warm_ms": { + "aggregate": 4012.3388919999998, + "samples": [4037.552543, 4012.3388919999998, 4005.346133000001] + }, + "changed_ms": { + "aggregate": 5226.147054000001, + "samples": [5226.147054000001, 5247.180337999998, 5180.184304999999] + }, + "total_ms": { + "aggregate": 22761.987719, + "samples": [22761.987719, 22790.397689999998, 22670.790537] + } + }, + "gates": { + "graph_parity": 1 + } + } + }, + "graph_receipts": [ + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 142, + "manifest": "ccafcd91d22aaccd886e978717499148823ca804132d64956f7f1ca9e9df1277" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 98, + "candidate_reparsed": 98 + }, + { + "scenario": "warm", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "6a32ba2f695eaba8d446d73dcb34696f5d09626b43698d5ed9248bdd4891495a" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 1968, + "edges": 4170, + "hash": "d1e73b293363196e0c88c8669b703a8ce6406cd60b817a1438f7c16d6a8896a1" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + } + ] + } + } + }, + "Declarations": { + "run": "https://github.com/abhigyanpatwari/GitNexus/actions/runs/40272393865", + "environment": { + "corpus": "declarations", + "harness_sha256": "e3a9d522a1fd7b0a93c4863bf8c3299f1f37127df12005142a9a81ff8417d029", + "cpus": [0, 1, 2, 3], + "node": "v22.23.3", + "identity_cache": "fresh private XDG_RUNTIME_DIR for every child on both sides" + }, + "comparisons": { + "aa": { + "snapshots": { + "reference": { + "metrics": { + "cold_ms": { + "aggregate": 9551.134566, + "samples": [9551.134566, 9824.026295, 9404.729941000001] + }, + "warm_ms": { + "aggregate": 2633.6338050000013, + "samples": [2582.1895320000003, 2633.6338050000013, 2637.239033] + }, + "changed_ms": { + "aggregate": 3544.0858340000013, + "samples": [3603.9926379999997, 3502.268441, 3544.0858340000013] + }, + "total_ms": { + "aggregate": 15737.316736, + "samples": [15737.316736, 15959.928541000001, 15586.054808000003] + } + }, + "gates": { + "graph_parity": 1 + } + }, + "candidate": { + "metrics": { + "cold_ms": { + "aggregate": 9387.599386, + "samples": [9659.857773, 9387.599386, 9382.705773000001] + }, + "warm_ms": { + "aggregate": 2635.7269969999998, + "samples": [2635.7269969999998, 2653.972619, 2612.905207] + }, + "changed_ms": { + "aggregate": 3535.517727000002, + "samples": [3535.517727000002, 3538.091756, 3494.1587480000017] + }, + "total_ms": { + "aggregate": 15579.663761, + "samples": [15831.102497000002, 15579.663761, 15489.769728000003] + } + }, + "gates": { + "graph_parity": 1 + } + } + }, + "graph_receipts": [ + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + } + ] + }, + "control": { + "snapshots": { + "reference": { + "metrics": { + "cold_ms": { + "aggregate": 9820.891036, + "samples": [9973.590131, 9820.891036, 9425.156427] + }, + "warm_ms": { + "aggregate": 2620.038533000001, + "samples": [2614.5033359999998, 2620.038533000001, 2621.719085999999] + }, + "changed_ms": { + "aggregate": 3530.4972159999998, + "samples": [3500.5629609999996, 3545.6961029999984, 3530.4972159999998] + }, + "total_ms": { + "aggregate": 15986.625672, + "samples": [16088.656428, 15986.625672, 15577.372728999999] + } + }, + "gates": { + "graph_parity": 1 + } + }, + "candidate": { + "metrics": { + "cold_ms": { + "aggregate": 9102.756594, + "samples": [9102.756594, 9090.239996, 9183.450958000001] + }, + "warm_ms": { + "aggregate": 2330.810039, + "samples": [2306.880000000001, 2330.810039, 2352.7963470000013] + }, + "changed_ms": { + "aggregate": 3202.8675539999986, + "samples": [3193.513699000001, 3202.8675539999986, 3223.514725000001] + }, + "total_ms": { + "aggregate": 14623.917588999999, + "samples": [14603.150293000002, 14623.917588999999, 14759.762030000004] + } + }, + "gates": { + "graph_parity": 1 + } + } + }, + "graph_receipts": [ + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + } + ] + }, + "initial": { + "snapshots": { + "reference": { + "metrics": { + "cold_ms": { + "aggregate": 9369.017782, + "samples": [9376.784626, 9317.390697, 9369.017782] + }, + "warm_ms": { + "aggregate": 2625.9175330000016, + "samples": [2625.9175330000016, 2610.395958000001, 2670.091103999999] + }, + "changed_ms": { + "aggregate": 3562.2680839999994, + "samples": [3599.269526, 3539.8330490000008, 3562.2680839999994] + }, + "total_ms": { + "aggregate": 15601.37697, + "samples": [15601.971685000002, 15467.619704000002, 15601.37697] + } + }, + "gates": { + "graph_parity": 1 + } + }, + "candidate": { + "metrics": { + "cold_ms": { + "aggregate": 9111.517404, + "samples": [9145.714691000001, 9050.379966, 9111.517404] + }, + "warm_ms": { + "aggregate": 2320.5296749999998, + "samples": [2320.5296749999998, 2315.4442039999994, 2334.540524] + }, + "changed_ms": { + "aggregate": 3227.7707830000018, + "samples": [3227.7707830000018, 3159.8233600000003, 3240.070385000001] + }, + "total_ms": { + "aggregate": 14686.128313000001, + "samples": [14694.015149000003, 14525.64753, 14686.128313000001] + } + }, + "gates": { + "graph_parity": 1 + } + } + }, + "graph_receipts": [ + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + }, + { + "manifest": { + "files": 65, + "manifest": "a8f8aa6206812f6bdcd24fce9d89dcf25d14eaf7b1c86ba49aea1ca64f729e40" + }, + "scenarios": [ + { + "scenario": "cold", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 65, + "candidate_reparsed": 65 + }, + { + "scenario": "warm", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "f9f0363efa933fcd0fdfbb64076e43bd7eb361f880251fda2de6dac1f716a0fa" + }, + "reference_reparsed": 0, + "candidate_reparsed": 0 + }, + { + "scenario": "changed", + "facts": { + "nodes": 2755, + "edges": 2754, + "hash": "58969c80be830cff4ba91511587aec077106936e7abe80d95f77ad284be2fcd4" + }, + "reference_reparsed": 1, + "candidate_reparsed": 1 + } + ] + } + ] + } + } + } + }, + "decisions": { + "control": { + "decision": "keep", + "eligible": true, + "next_measurement": "none", + "target_reached": false, + "improved_objectives": ["total_ms", "warm_ms", "changed_ms"], + "violated_objectives": [], + "comparisons": { + "total_ms": { + "verdict": "improved", + "delta": 996.5652770000052, + "relative": 0.041591831469722736, + "violated": false + }, + "cold_ms": { + "verdict": "inconclusive", + "delta": 347.10366500000055, + "relative": 0.024807713955235854, + "violated": false + }, + "warm_ms": { + "verdict": "improved", + "delta": 467.90281700000014, + "relative": 0.10370839686931428, + "violated": false + }, + "changed_ms": { + "verdict": "improved", + "delta": 364.62851899999805, + "relative": 0.06520308135889427, + "violated": false + } + }, + "primary_delta": 996.5652770000052, + "rank_score": 0.041591831469722736, + "regressions": [], + "holdout": { + "comparisons": { + "total_ms": { + "verdict": "improved", + "delta": 1362.7080830000014, + "relative": 0.08524050734400665, + "violated": false + }, + "cold_ms": { + "verdict": "inconclusive", + "delta": 718.1344420000005, + "relative": 0.07312314527954411, + "violated": false + }, + "warm_ms": { + "verdict": "improved", + "delta": 289.22849400000086, + "relative": 0.11039093141459563, + "violated": false + }, + "changed_ms": { + "verdict": "improved", + "delta": 327.6296620000012, + "relative": 0.0927998641424226, + "violated": false + } + }, + "improved_objectives": ["total_ms", "warm_ms", "changed_ms"], + "violated_objectives": [], + "agrees": true, + "decision": "keep", + "reason": null + }, + "reason": "improved total_ms, warm_ms, changed_ms without violating other required objectives" + }, + "initial": { + "decision": "keep", + "eligible": true, + "next_measurement": "none", + "target_reached": false, + "improved_objectives": ["total_ms", "warm_ms", "changed_ms"], + "violated_objectives": [], + "comparisons": { + "total_ms": { + "verdict": "improved", + "delta": 1396.8737419999998, + "relative": 0.05782034655296125, + "violated": false + }, + "cold_ms": { + "verdict": "inconclusive", + "delta": 473.41547300000093, + "relative": 0.033883876062860384, + "violated": false + }, + "warm_ms": { + "verdict": "improved", + "delta": 526.1384770000004, + "relative": 0.1159284125979742, + "violated": false + }, + "changed_ms": { + "verdict": "improved", + "delta": 339.1704409999984, + "relative": 0.060943592401460724, + "violated": false + } + }, + "primary_delta": 1396.8737419999998, + "rank_score": 0.05782034655296125, + "regressions": [], + "holdout": { + "comparisons": { + "total_ms": { + "verdict": "improved", + "delta": 915.2486569999983, + "relative": 0.058664607538163875, + "violated": false + }, + "cold_ms": { + "verdict": "inconclusive", + "delta": 257.50037800000064, + "relative": 0.027484244772671584, + "violated": false + }, + "warm_ms": { + "verdict": "improved", + "delta": 305.38785800000187, + "relative": 0.11629758138333801, + "violated": false + }, + "changed_ms": { + "verdict": "improved", + "delta": 334.4973009999976, + "relative": 0.0939000920515778, + "violated": false + } + }, + "improved_objectives": ["total_ms", "warm_ms", "changed_ms"], + "violated_objectives": [], + "agrees": true, + "decision": "keep", + "reason": null + }, + "reason": "improved total_ms, warm_ms, changed_ms without violating other required objectives" + } + } +} diff --git a/gitnexus/src/core/analyzer-identity.ts b/gitnexus/src/core/analyzer-identity.ts index 5782a5724..9bd3902a1 100644 --- a/gitnexus/src/core/analyzer-identity.ts +++ b/gitnexus/src/core/analyzer-identity.ts @@ -2241,8 +2241,13 @@ function loadIdentityCache( } const CACHE_GUARD_PROBE_SCRIPT = String.raw` -const fs = require('node:fs/promises'); +const fs = require('node:fs'); +const { performance } = require('node:perf_hooks'); const crypto = require('node:crypto'); +const syncFs = { + lstat: fs.lstatSync, stat: fs.statSync, + readlink: fs.readlinkSync, readdir: fs.readdirSync, +}; const state = (value) => ({ dev: String(value.dev), ino: String(value.ino), mode: String(value.mode), nlink: String(value.nlink), size: String(value.size), @@ -2272,30 +2277,30 @@ const inventoryDigest = (entries) => { for (const entry of normalized) frame(hash, [entry.name, entry.kind]); return 'sha256:' + hash.digest('hex'); }; -const probe = async (request) => { +const probe = async (request, io) => { try { - const link = await fs.lstat(request.absolutePath, { bigint: true }); + const link = await io.lstat(request.absolutePath, { bigint: true }); const type = link.isDirectory() ? 'directory' : link.isFile() ? 'file' : link.isSymbolicLink() ? 'symlink' : 'other'; if (request.mode === 'link') return { type, state: state(link), - ...(type === 'symlink' ? { symlinkTarget: await fs.readlink(request.absolutePath) } : {}), + ...(type === 'symlink' ? { symlinkTarget: await io.readlink(request.absolutePath) } : {}), }; if (request.mode === 'directory-inventory') { if (!link.isDirectory() || link.isSymbolicLink()) return null; const entriesDigest = inventoryDigest( - await fs.readdir(request.absolutePath, { withFileTypes: true }), + await io.readdir(request.absolutePath, { withFileTypes: true }), ); - const after = await fs.lstat(request.absolutePath, { bigint: true }); + const after = await io.lstat(request.absolutePath, { bigint: true }); if (JSON.stringify(state(link)) !== JSON.stringify(state(after))) return null; return { type: 'directory-inventory', state: state(after), entriesDigest }; } - const target = link.isFile() ? link : await fs.stat(request.absolutePath, { bigint: true }); + const target = link.isFile() ? link : await io.stat(request.absolutePath, { bigint: true }); if (!target.isFile()) return null; const result = { type: 'readable-file', state: { link: state(link), target: state(target) } }; - if (link.isSymbolicLink()) result.state.symlinkTarget = await fs.readlink(request.absolutePath); + if (link.isSymbolicLink()) result.state.symlinkTarget = await io.readlink(request.absolutePath); return result; } catch { return null; } }; @@ -2305,9 +2310,29 @@ process.stdin.on('data', (chunk) => { input += chunk; }); process.stdin.on('end', async () => { try { const requests = JSON.parse(input); - const results = []; - for (let offset = 0; offset < requests.length; offset += 512) { - results.push(...await Promise.all(requests.slice(offset, offset + 512).map(probe))); + const results = new Array(requests.length); + // Local stats are cheaper without thread-pool dispatch. Sample across the + // install tree so slow dependency mounts still use concurrent async I/O. + const sampleCount = Math.min(16, requests.length); + const started = performance.now(); + for (let sample = 0; sample < sampleCount; sample += 1) { + const index = Math.floor(sample * requests.length / sampleCount); + results[index] = await probe(requests[index], syncFs); + if (performance.now() - started >= 8) break; + } + const useSync = performance.now() - started < 8; + if (useSync) { + for (let index = 0; index < requests.length; index += 1) { + if (results[index] === undefined) results[index] = await probe(requests[index], syncFs); + } + } else { + for (let offset = 0; offset < requests.length; offset += 512) { + await Promise.all(requests.slice(offset, offset + 512).map(async (request, index) => { + if (results[offset + index] === undefined) { + results[offset + index] = await probe(request, fs.promises); + } + })); + } } process.stdout.write(JSON.stringify(results)); } catch { process.exitCode = 1; } diff --git a/gitnexus/test/unit/analyzer-identity-guard-io.test.ts b/gitnexus/test/unit/analyzer-identity-guard-io.test.ts new file mode 100644 index 000000000..f89622f5e --- /dev/null +++ b/gitnexus/test/unit/analyzer-identity-guard-io.test.ts @@ -0,0 +1,189 @@ +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; +import { mkdir, symlink, writeFile } from 'node:fs/promises'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { createTempDir, type TestDBHandle } from '../helpers/test-db.js'; + +const captured = vi.hoisted(() => ({ script: '' })); +vi.mock('node:child_process', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + spawnSync: (...args: Parameters) => { + const argv = args[1]; + if (Array.isArray(argv) && argv.includes('--input-type=commonjs')) { + captured.script = argv[argv.indexOf('-e') + 1]; + // Let identity resolution fall back to the real direct validator. + return { status: 1, stdout: '', stderr: '' }; + } + return actual.spawnSync(...args); + }, + }; +}); + +import { + _clearAnalyzerIdentityProcessCacheForTests, + resolveAnalyzerRunnerIdentity, +} from '../../src/core/analyzer-identity.js'; + +type Request = { absolutePath: string; mode: 'link' | 'readable-file' | 'directory-inventory' }; +type Result = { + type: string; + state: unknown; + entriesDigest?: string; + symlinkTarget?: string; +} | null; + +// Exercise the actual subprocess script captured through the public resolver. +// A deterministic clock chooses the I/O route without timing-sensitive tests. +async function runProbe(requests: Request[], slow: boolean, mutateDirectory?: string) { + const { spawnSync } = + await vi.importActual('node:child_process'); + const instrumentation = ` + const probeFs = require('node:fs'); + let ticks = 0; + Object.defineProperty(require('node:perf_hooks').performance, 'now', { + value: () => ticks++ * ${slow ? 100 : 0}, + }); + const counts = { sync: 0, async: 0 }; + const mutationDirectory = ${JSON.stringify(mutateDirectory ?? null)}; + let mutated = false; + const afterRead = (file) => { + if (!mutated && file === mutationDirectory) { + mutated = true; + probeFs.writeFileSync(require('node:path').join(file, 'added'), 'changed'); + } + }; + for (const name of ['lstat', 'stat', 'readlink', 'readdir']) { + const originalSync = probeFs[name + 'Sync']; + probeFs[name + 'Sync'] = (...args) => { + counts.sync++; + const result = originalSync(...args); + if (name === 'readdir') afterRead(args[0]); + return result; + }; + const originalAsync = probeFs.promises[name]; + probeFs.promises[name] = async (...args) => { + counts.async++; + const result = await originalAsync(...args); + if (name === 'readdir') afterRead(args[0]); + return result; + }; + } + process.on('exit', () => process.stderr.write(JSON.stringify(counts))); + `; + const child = spawnSync( + process.execPath, + ['--input-type=commonjs', '-e', instrumentation + captured.script], + { + input: JSON.stringify(requests), + encoding: 'utf8', + timeout: 10_000, + }, + ); + expect(child.error).toBeUndefined(); + expect(child.status, child.stderr).toBe(0); + return { + results: JSON.parse(child.stdout) as Result[], + counts: JSON.parse(child.stderr) as { sync: number; async: number }, + }; +} + +describe('identity guard subprocess I/O', () => { + let fixture: TestDBHandle; + let file: string; + let directory: string; + + beforeAll(async () => { + fixture = await createTempDir(); + directory = path.join(fixture.dbPath, 'src'); + await mkdir(directory); + await writeFile( + path.join(fixture.dbPath, 'package.json'), + '{"name":"guard-io","version":"1.0.0"}', + ); + for (let index = 0; index < 140; index++) { + await writeFile(path.join(directory, `file-${index}.ts`), `export const value = ${index};`); + } + file = path.join(directory, 'file-0.ts'); + vi.stubEnv('GITNEXUS_ANALYZER_IDENTITY_IN_PROCESS_GUARDS', '0'); + _clearAnalyzerIdentityProcessCacheForTests(); + resolveAnalyzerRunnerIdentity(pathToFileURL(file).href, { + cacheDirectory: path.join(fixture.dbPath, 'cache'), + }); + expect(captured.script).not.toBe(''); + }); + + afterAll(async () => { + vi.unstubAllEnvs(); + _clearAnalyzerIdentityProcessCacheForTests(); + await fixture?.cleanup(); + }); + + it('returns identical ordered snapshots and failures across batch boundaries on both routes', async () => { + const cases: Request[] = [ + { absolutePath: file, mode: 'link' }, + { absolutePath: directory, mode: 'directory-inventory' }, + { absolutePath: file, mode: 'readable-file' }, + { absolutePath: path.join(fixture.dbPath, 'missing'), mode: 'link' }, + { absolutePath: directory, mode: 'readable-file' }, + { absolutePath: file, mode: 'directory-inventory' }, + ]; + const requests = Array.from({ length: 529 }, (_, index) => cases[index % cases.length]); + const fast = await runProbe(requests, false); + const slow = await runProbe(requests, true); + expect(fast.counts.async).toBe(0); + expect(fast.counts.sync).toBeGreaterThan(requests.length); + // A slow first probe exhausts the sample budget; the rest stay concurrent. + expect(slow.counts.sync).toBe(1); + expect(slow.counts.async).toBeGreaterThan(512); + expect(slow.results).toEqual(fast.results); + expect(fast.results).toHaveLength(requests.length); + for (let index = 0; index < requests.length; index++) { + const result = fast.results[index]; + if (index % cases.length >= 3) expect(result).toBeNull(); + else + expect(result?.type).toBe( + ['file', 'directory-inventory', 'readable-file'][index % cases.length], + ); + } + expect(fast.results[1]?.entriesDigest).toMatch(/^sha256:[a-f0-9]{64}$/); + }); + + it.each([false, true])('rejects an inventory changed during a probe (slow=%s)', async (slow) => { + const changing = path.join(fixture.dbPath, `changing-${slow}`); + await mkdir(changing); + const requests: Request[] = Array.from({ length: 529 }, () => ({ + absolutePath: file, + mode: 'link', + })); + // Index 1 is outside the distributed sample, exercising the selected route. + requests[1] = { absolutePath: changing, mode: 'directory-inventory' }; + const result = await runProbe(requests, slow, changing); + expect(result.results[1]).toBeNull(); + expect(result.results[0]?.type).toBe('file'); + expect(result.results[528]?.type).toBe('file'); + }); + + it.skipIf(process.platform === 'win32')( + 'preserves symlink targets and dangling-link failures on both routes', + async () => { + const link = path.join(fixture.dbPath, 'linked.ts'); + const dangling = path.join(fixture.dbPath, 'dangling.ts'); + await symlink(file, link); + await symlink(path.join(fixture.dbPath, 'absent.ts'), dangling); + const cases: Request[] = [ + { absolutePath: link, mode: 'link' }, + { absolutePath: link, mode: 'readable-file' }, + { absolutePath: dangling, mode: 'readable-file' }, + ]; + const requests = Array.from({ length: 140 }, (_, index) => cases[index % cases.length]); + const fast = await runProbe(requests, false); + const slow = await runProbe(requests, true); + expect(slow.results).toEqual(fast.results); + expect(fast.results[0]?.symlinkTarget).toBe(file); + expect(fast.results[1]?.state).toMatchObject({ symlinkTarget: file }); + expect(fast.results[2]).toBeNull(); + }, + ); +});