Skip to content

Commit e2cb100

Browse files
author
DavidQ
committed
Level 18.2 Boundary Hardening (Overlay Slice)
- Enforced layer boundaries in overlay runtime - Removed cross-layer leakage - Maintained test pass status
1 parent 407cf72 commit e2cb100

7 files changed

Lines changed: 72 additions & 78 deletions

File tree

docs/dev/CODEX_COMMANDS.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
# Codex Command
2-
3-
MODEL: GPT-5.4-codex
1+
MODEL: GPT-5.3-codex
42
REASONING: high
53

6-
Use the repository root as the working directory.
7-
8-
Implement `BUILD_PR_LEVEL_18_1_ENGINE_USAGE_ENFORCEMENT_AUDIT_SLICE` exactly as specified in `docs/pr/BUILD_PR_LEVEL_18_1_ENGINE_USAGE_ENFORCEMENT_AUDIT_SLICE.md`.
9-
10-
Requirements:
11-
- keep scope bounded to the overlay runtime hardening slice
12-
- do not scan or edit unrelated repo areas
13-
- migrate only clearly duplicated local logic to already-existing stable `src/engine` or `src/shared` surfaces
14-
- update or add only the smallest necessary tests
15-
- update roadmap status markers only for directly completed work
16-
- package the finished repo-structured ZIP to:
17-
`<project folder>/tmp/BUILD_PR_LEVEL_18_1_ENGINE_USAGE_ENFORCEMENT_AUDIT_SLICE.zip`
4+
COMMAND:
5+
Apply boundary enforcement rules to overlay runtime:
6+
- Remove cross-layer leakage
7+
- Enforce engine/shared separation
8+
- Validate imports
189

19-
Output required in the ZIP:
20-
- implementation changes
21-
- updated roadmap status markers
22-
- any validation-backed test changes
23-
- `docs/dev/reports/change_summary.txt`
24-
- `docs/dev/reports/validation_checklist.txt`
25-
- `docs/dev/reports/file_tree.txt`
10+
Output ZIP to:
11+
<project folder>/tmp/BUILD_PR_LEVEL_18_2_BOUNDARY_HARDENING_OVERLAY_SLICE.zip

docs/dev/COMMIT_COMMENT.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
Level 18 hardening: audit bounded overlay runtime slice for engine/shared usage, remove local reimplementation where stable shared surfaces already exist, and add validation-backed enforcement
2-
BUILD_PR_LEVEL_18_1_ENGINE_USAGE_ENFORCEMENT_AUDIT_SLICE
1+
Level 18.2 Boundary Hardening (Overlay Slice)
2+
3+
- Enforced layer boundaries in overlay runtime
4+
- Removed cross-layer leakage
5+
- Maintained test pass status
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
Validation checklist for Codex:
2-
- [x] Run targeted tests covering edited overlay runtime files
3-
Command: custom Node runner with alias hooks for:
4-
- `./tests/runtime/Phase19OverlayExpansionFramework.test.mjs`
5-
- `./tests/runtime/Phase17OverlayGameplayRuntimeIntegration.test.mjs`
6-
- `./tests/runtime/Phase17OverlayInputEdgeCases.test.mjs`
7-
Result: PASS all three tests.
8-
- [x] Run existing overlay integration tests impacted by edited imports
9-
Covered by:
10-
- `Phase19OverlayExpansionFramework.test.mjs` (includes pointer/gesture/runtime coverage and new enforcement assertion)
11-
- `Phase17OverlayGameplayRuntimeIntegration.test.mjs`
12-
- `Phase17OverlayInputEdgeCases.test.mjs`
13-
- [x] Confirm no unrelated files changed
14-
Changed implementation/test/roadmap files are limited to this audit slice plus required report artifacts.
15-
- [x] Confirm no gameplay behavior drift beyond duplicate-removal remediation
16-
Existing Phase17 and Phase19 overlay runtime integration tests passed after migration.
17-
- [x] Confirm roadmap wording unchanged except status markers
18-
Updated only marker states in Level 18 Track A items.
19-
- [x] Confirm ZIP written to `<project folder>/tmp/BUILD_PR_LEVEL_18_1_ENGINE_USAGE_ENFORCEMENT_AUDIT_SLICE.zip`
1+
[ ] overlay tests pass
2+
[ ] no regressions
3+
[ ] boundaries enforced

docs/dev/roadmaps/MASTER_ROADMAP_HIGH_LEVEL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,9 @@
728728
- [ ] remove sample-specific logic from engine paths
729729

730730
### Track B — Boundary Hardening
731-
- [ ] enforce engine vs shared vs game vs tool boundaries
732-
- [ ] eliminate cross-layer leakage
733-
- [ ] validate dependency direction rules across repo
731+
- [.] enforce engine vs shared vs game vs tool boundaries
732+
- [.] eliminate cross-layer leakage
733+
- [.] validate dependency direction rules across repo
734734
- [ ] remove accidental coupling
735735

736736
### Track C — Contract Stabilization
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# BUILD PR LEVEL 18.2 — Boundary Hardening (Overlay Slice)
2+
3+
Purpose:
4+
Enforce clean boundaries for overlay runtime without repo-wide churn.
5+
6+
Scope:
7+
- Overlay runtime only (phase-17 shared overlay)
8+
- No engine-wide refactor
9+
10+
Validation:
11+
- Overlay tests pass
12+
- No regression in samples

samples/phase-17/shared/overlayGameplayRuntime.js

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import {
99
isOverlayRuntimeToggleModifierActive,
1010
LEVEL17_OVERLAY_CYCLE_KEY,
1111
} from '/samples/phase-17/shared/overlayCycleInput.js';
12+
import { cloneJsonData, safeJsonParse, safeJsonStringify } from '/src/shared/io/index.js';
1213
import { asFiniteNumber } from '/src/shared/number/index.js';
1314

1415
const overlayRuntimePreferenceMemoryStore = new Map();
1516
const OVERLAY_RUNTIME_SHARE_PACKAGE_FORMAT = 'overlay-runtime-share-package';
1617
const OVERLAY_RUNTIME_SHARE_PACKAGE_VERSION = 1;
1718
const OVERLAY_RUNTIME_PROFILE_SCHEMA_VERSION = 1;
19+
const OVERLAY_RUNTIME_INVALID_JSON_PARSE = Symbol('overlay-runtime-invalid-json-parse');
1820
const OVERLAY_RUNTIME_DEFAULT_PRESET_DEFINITIONS = Object.freeze([
1921
Object.freeze({
2022
id: 'minimal',
@@ -234,17 +236,6 @@ function normalizeOverlayRuntimePreferenceStorageKey(preferenceStorageKey) {
234236
return String(preferenceStorageKey || '').trim();
235237
}
236238

237-
function cloneJsonCompatibleValue(value) {
238-
if (value === null || value === undefined) {
239-
return null;
240-
}
241-
try {
242-
return JSON.parse(JSON.stringify(value));
243-
} catch {
244-
return null;
245-
}
246-
}
247-
248239
function readOverlayRuntimePreferencePayloadFromStorage(preferenceStorageKey, storage = null) {
249240
const key = normalizeOverlayRuntimePreferenceStorageKey(preferenceStorageKey);
250241
if (!key) {
@@ -269,20 +260,16 @@ function readOverlayRuntimePreferencePayloadFromStorage(preferenceStorageKey, st
269260
return null;
270261
}
271262

272-
try {
273-
const parsed = JSON.parse(raw);
274-
return parsed && typeof parsed === 'object' ? parsed : null;
275-
} catch {
276-
return null;
277-
}
263+
const parsed = safeJsonParse(raw, null);
264+
return parsed && typeof parsed === 'object' ? parsed : null;
278265
}
279266

280267
function writeOverlayRuntimePreferencePayloadToStorage(preferenceStorageKey, payload, storage = null) {
281268
const key = normalizeOverlayRuntimePreferenceStorageKey(preferenceStorageKey);
282269
if (!key) {
283270
return false;
284271
}
285-
const serialized = JSON.stringify(payload || {});
272+
const serialized = safeJsonStringify(payload || {}, '{}');
286273
overlayRuntimePreferenceMemoryStore.set(key, serialized);
287274

288275
const storageWriter = storage && typeof storage.setItem === 'function'
@@ -376,7 +363,7 @@ function validateOverlayRuntimePreferencePayload(payload) {
376363
keybindProfile.contextInputMap = null;
377364
keybindProfile.contextInputMapSpecified = true;
378365
} else if (contextInputMap && typeof contextInputMap === 'object' && !Array.isArray(contextInputMap)) {
379-
const clonedContextInputMap = cloneJsonCompatibleValue(contextInputMap);
366+
const clonedContextInputMap = cloneJsonData(contextInputMap);
380367
if (clonedContextInputMap && typeof clonedContextInputMap === 'object') {
381368
keybindProfile.contextInputMap = clonedContextInputMap;
382369
keybindProfile.contextInputMapSpecified = true;
@@ -436,7 +423,7 @@ function applyOverlayRuntimePreferencePayload(runtime, validatedPayload) {
436423
if (keybindProfile.contextInputMapSpecified === true) {
437424
runtime.interactionContextInputMap = keybindProfile.contextInputMap === null
438425
? null
439-
: (cloneJsonCompatibleValue(keybindProfile.contextInputMap) ?? null);
426+
: (cloneJsonData(keybindProfile.contextInputMap) ?? null);
440427
}
441428
}
442429
return true;
@@ -455,7 +442,7 @@ function createOverlayRuntimePreferencePayloadFromValidated(validatedPayload) {
455442
payload.visibility = validatedPayload.visibility === true;
456443
}
457444
if (validatedPayload.hasLayout) {
458-
payload.layout = cloneJsonCompatibleValue(validatedPayload.layout) || {};
445+
payload.layout = cloneJsonData(validatedPayload.layout) || {};
459446
}
460447
if (validatedPayload.hasKeybindProfile) {
461448
const keybindProfile = {};
@@ -468,7 +455,7 @@ function createOverlayRuntimePreferencePayloadFromValidated(validatedPayload) {
468455
if (validatedPayload.keybindProfile.contextInputMapSpecified === true) {
469456
keybindProfile.contextInputMap = validatedPayload.keybindProfile.contextInputMap === null
470457
? null
471-
: (cloneJsonCompatibleValue(validatedPayload.keybindProfile.contextInputMap) || {});
458+
: (cloneJsonData(validatedPayload.keybindProfile.contextInputMap) || {});
472459
}
473460
payload.keybindProfile = keybindProfile;
474461
}
@@ -1856,7 +1843,7 @@ export function setOverlayGameplayRuntimeKeybindProfile(runtime, { id = '', cycl
18561843
}
18571844
if (contextInputMap !== undefined) {
18581845
runtime.interactionContextInputMap = contextInputMap && typeof contextInputMap === 'object'
1859-
? cloneJsonCompatibleValue(contextInputMap) ?? contextInputMap
1846+
? cloneJsonData(contextInputMap) ?? contextInputMap
18601847
: null;
18611848
}
18621849
saveOverlayGameplayRuntimePreferences(runtime, { silent: true });
@@ -1881,7 +1868,7 @@ export function getOverlayGameplayRuntimePreferencesSnapshot(runtime) {
18811868
cycleKey: String(runtime.interactionCycleKey || LEVEL17_OVERLAY_CYCLE_KEY).trim() || LEVEL17_OVERLAY_CYCLE_KEY,
18821869
};
18831870
if (runtime.interactionContextInputMap && typeof runtime.interactionContextInputMap === 'object') {
1884-
const clonedContextInputMap = cloneJsonCompatibleValue(runtime.interactionContextInputMap);
1871+
const clonedContextInputMap = cloneJsonData(runtime.interactionContextInputMap);
18851872
if (clonedContextInputMap && typeof clonedContextInputMap === 'object') {
18861873
keybindProfile.contextInputMap = clonedContextInputMap;
18871874
}
@@ -1997,16 +1984,15 @@ export function importOverlayGameplayRuntimeProfile(runtime, profileInput, optio
19971984

19981985
let parsedInput = null;
19991986
if (typeof profileInput === 'string') {
2000-
try {
2001-
parsedInput = JSON.parse(profileInput);
2002-
} catch {
1987+
parsedInput = safeJsonParse(profileInput, OVERLAY_RUNTIME_INVALID_JSON_PARSE);
1988+
if (parsedInput === OVERLAY_RUNTIME_INVALID_JSON_PARSE) {
20031989
return Object.freeze({
20041990
success: false,
20051991
errors: Object.freeze(['Overlay runtime profile JSON is invalid.']),
20061992
});
20071993
}
20081994
} else {
2009-
parsedInput = cloneJsonCompatibleValue(profileInput);
1995+
parsedInput = cloneJsonData(profileInput);
20101996
}
20111997

20121998
const validated = validateOverlayRuntimePreferencePayload(parsedInput);
@@ -2039,9 +2025,8 @@ export function importOverlayGameplayRuntimeSharePackage(runtime, sharePackageIn
20392025

20402026
let parsedInput = null;
20412027
if (typeof sharePackageInput === 'string') {
2042-
try {
2043-
parsedInput = JSON.parse(sharePackageInput);
2044-
} catch {
2028+
parsedInput = safeJsonParse(sharePackageInput, OVERLAY_RUNTIME_INVALID_JSON_PARSE);
2029+
if (parsedInput === OVERLAY_RUNTIME_INVALID_JSON_PARSE) {
20452030
return Object.freeze({
20462031
success: false,
20472032
errors: Object.freeze(['Overlay runtime share package JSON is invalid.']),
@@ -2050,7 +2035,7 @@ export function importOverlayGameplayRuntimeSharePackage(runtime, sharePackageIn
20502035
});
20512036
}
20522037
} else {
2053-
parsedInput = cloneJsonCompatibleValue(sharePackageInput);
2038+
parsedInput = cloneJsonData(sharePackageInput);
20542039
}
20552040

20562041
const validated = validateOverlayRuntimeSharePackagePayload(parsedInput, runtime);

tests/runtime/Phase19OverlayExpansionFramework.test.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,40 @@ function assertOverlayRuntimeSliceUsesSharedFiniteNumberHelper() {
7474
new URL('../../samples/phase-17/shared/overlayGameplayRuntime.js', import.meta.url),
7575
'utf8'
7676
);
77+
const importSpecifiers = Array.from(
78+
runtimeSource.matchAll(/^\s*import\s+[\s\S]*?\sfrom\s+['"]([^'"]+)['"]\s*;?\s*$/gm),
79+
(match) => String(match[1] || '').trim()
80+
);
7781
assert.equal(
7882
runtimeSource.includes("import { asFiniteNumber } from '/src/shared/number/index.js';"),
7983
true,
8084
'Overlay runtime slice should import finite-number normalization from shared number helpers.'
8185
);
86+
assert.equal(
87+
runtimeSource.includes("import { cloneJsonData, safeJsonParse, safeJsonStringify } from '/src/shared/io/index.js';"),
88+
true,
89+
'Overlay runtime slice should import shared JSON IO helpers instead of local JSON clone/parse/stringify logic.'
90+
);
8291
assert.equal(
8392
runtimeSource.includes('function normalizePointerNumber('),
8493
false,
8594
'Overlay runtime slice should not keep a local duplicate pointer-number normalization helper.'
8695
);
96+
assert.equal(
97+
runtimeSource.includes('function cloneJsonCompatibleValue('),
98+
false,
99+
'Overlay runtime slice should not keep a local duplicate JSON-clone helper.'
100+
);
101+
assert.equal(
102+
importSpecifiers.some((specifier) => specifier.startsWith('/src/engine/')),
103+
false,
104+
'Overlay runtime slice boundary hardening should avoid direct engine-layer imports.'
105+
);
106+
assert.equal(
107+
importSpecifiers.some((specifier) => specifier.startsWith('../') || specifier.startsWith('./')),
108+
false,
109+
'Overlay runtime slice boundary hardening should use root-layer imports and avoid relative cross-layer traversal.'
110+
);
87111
}
88112

89113
function assertExpansionRegistrationAndCompatibility() {

0 commit comments

Comments
 (0)