Commit 6f16513
refactor(phase-2-d-helpers): thread wasmRuntime through route-chain helpers
Phase 2-C deferred 10 (originally counted as 8) getWASMRuntime() call
sites with "Phase 2-D (deferred)" comments. Call-graph mapping during
this ticket split them into three categories:
1. Route-chain helpers (7 sites in api/storage.ts + api/media.ts):
convert to threaded wasmRuntime: WASMRuntime parameter.
2. Service-layer helpers (2 sites in services/media/): document as
intentional architectural-boundary ambient.
3. Class-method on bootstrap-constructed service (1 site in
IPFSStorage): same documentation pattern.
4. Module-level eager preloads (2 sites in api/media.ts): turned out
not to use the WASM runtime at all (pure file reads); the
getWASMRuntime value-import was unused at module-level once
route-chain helpers were threaded — dropped entirely.
Function signatures changed for 7 helpers across 3 files
(api/storage.ts: loadRendererBinary, decryptAssetTwoLayer,
renderViaWASM; api/media.ts: splitInitForTrackWithFallback,
stripInitViaWASM, decryptSegmentViaWASM). All callers updated:
4 in storage.ts, 3 in media.ts /segment route, 1 in gateway.ts
(skills-install handler).
Notable difference from Phase 2-D: compiled JS is NOT byte-identical
(function signatures changed). Behavior equivalence preserved by
passing the exact same singleton that ambient access would have
returned — verified via bootstrap-time app.locals.wasmRuntime
assignment using the same getWASMRuntime() singleton.
Discovery during execution: recoverCEKAndFetchData doesn't actually
need threading — the runtime usage at the deferral-comment site was
inside decryptAssetTwoLayer's scope (after the recoverCEKAndFetchData
call returned), not inside recoverCEKAndFetchData's body. Spotted
by tsc when I prematurely added a 3rd arg; reverted in <1 minute.
Made ipfsService required in decryptAssetTwoLayer (was optional;
both callers always pass it).
3 service-internal sites + 2 module-level preloads documented with
explicit "intentional architectural-boundary ambient" classification
comments pointing at PHASE-2-D-HELPERS-CLEANUP.md ticket. Future
audits should not flag these; they're tracked as candidates for
the eventual capsule-boundary refactor (constructor injection,
pipeline context objects, capability tokens).
Validation:
- tsc --noEmit clean on FIRST attempt (no compiler bugs surfaced;
unlike 2-C/2-Globals, route-chain sites were already properly
typed under the getWASMRuntime() return type)
- npm run build:backend clean
- npm run test:unit 7/7 in 52.2 ms
- ReadLints zero on 6 modified files
- Live /api/health smoke: HTTP 200, db=connected, ipfs=available;
Sasha's dev session continues operating normally through hot-reload
After this commit, every route-chain consumer site for WASMRuntime
in pc2-node/src now uses explicit dependency injection. Combined
with Phases 2-A/2-B/2-C/2-D/2-Globals, all mechanical-pattern
blockers (#1 + #2) are now functionally exhausted at the Express
request boundary. Remaining audit work is exclusively architectural.
Held behind Mac launcher 48-72h soak gate before release-branch
merge. See PHASE-2-D-HELPERS-CLEANUP.md for the full execution log
and CAPSULE_READINESS_REPORT.md §5.10 for audit-score impact.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 8f7698e commit 6f16513
10 files changed
Lines changed: 374 additions & 37 deletions
File tree
- .cursor/tasks/OPTIMISATION-AND-REFACTORING-2026-05
- pc2-node/src
- api
- services/media
- storage
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | | - | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
Lines changed: 101 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1109 | 1109 | | |
1110 | 1110 | | |
1111 | 1111 | | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
1112 | 1213 | | |
1113 | 1214 | | |
1114 | 1215 | | |
| |||
0 commit comments