Skip to content

Commit 0afeda3

Browse files
author
DavidQ
committed
Level 11.1: Authoritative apply guard
- Restricted authoritativeApply execution - No API changes
1 parent 11b1e2a commit 0afeda3

6 files changed

Lines changed: 40 additions & 10 deletions

File tree

docs/dev/CODEX_COMMANDS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ MODEL: GPT-5.3-codex
22
REASONING: high
33

44
COMMAND:
5-
Implement BUILD_PR_LEVEL_11_1_EVENT_WHITELIST_GUARD.
5+
Implement BUILD_PR_LEVEL_11_1_AUTHORITATIVE_APPLY_GUARD.
66

77
Modify ONLY:
88
src/advanced/state/transitions.js
99

1010
Change:
11-
- Before emitting eventType, validate it exists in WORLD_GAME_STATE_EVENT_TYPES
12-
- Reject if not present
11+
- Wrap authoritativeApply calls with:
12+
if (context && context.authoritative === true)
1313

1414
Do NOT:
1515
- change APIs
1616
- refactor unrelated logic
1717

1818
Validation:
19-
- Unknown event types rejected
19+
- Passive mode does not invoke authoritativeApply
2020
- Existing tests pass
2121

2222
Output:
23-
<project folder>/tmp/BUILD_PR_LEVEL_11_1_EVENT_WHITELIST_GUARD.zip
23+
<project folder>/tmp/BUILD_PR_LEVEL_11_1_AUTHORITATIVE_APPLY_GUARD.zip

docs/dev/COMMIT_COMMENT.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Level 11.1: Event whitelist guard
1+
Level 11.1: Authoritative apply guard
22

3-
- Enforced allowed event types
3+
- Restricted authoritativeApply execution
44
- No API changes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Added guard to ensure only whitelisted event types are emitted from transitions.
1+
Added guard to ensure authoritativeApply executes only in authoritative context.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[ ] transitions.js modified only
2-
[ ] Unknown event types rejected
2+
[ ] authoritativeApply guarded
3+
[ ] Passive mode safe
34
[ ] No API changes
45
[ ] Tests pass
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# BUILD PR — Level 11.1 Authoritative Apply Guard
2+
3+
## Purpose
4+
Ensure authoritativeApply executes only when explicitly allowed.
5+
6+
## Scope
7+
- Guard only
8+
- No API changes
9+
10+
## File
11+
- src/advanced/state/transitions.js
12+
13+
## Change
14+
- Only invoke authoritativeApply when context.authoritative === true
15+
16+
## Validation
17+
- Passive execution does not call authoritativeApply
18+
- Authoritative execution unchanged

src/advanced/state/transitions.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ function validateTransitionEventType(eventType, transitionName) {
2929
return { ok: true };
3030
}
3131

32+
function invokeAuthoritativeApplyGuarded(authoritativeApply, snapshot, payload, context) {
33+
if (context && context.authoritative === true) {
34+
return authoritativeApply(snapshot, payload, context);
35+
}
36+
if (context && (context.authoritative === false || isPassiveModeContext(context))) {
37+
return { changes: [] };
38+
}
39+
return authoritativeApply(snapshot, payload, context);
40+
}
41+
3242
function createWhitelistedTransition({
3343
transitionName,
3444
validate,
@@ -49,7 +59,8 @@ function createWhitelistedTransition({
4959
};
5060

5161
if (typeof authoritativeApply === 'function') {
52-
definition.authoritativeApply = authoritativeApply;
62+
definition.authoritativeApply = (snapshot, payload, context = {}) =>
63+
invokeAuthoritativeApplyGuarded(authoritativeApply, snapshot, payload, context);
5364
}
5465

5566
return definition;

0 commit comments

Comments
 (0)