feat(config): add shared configuration core - #404
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ee368f779
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const digest = await sha256Hex(rawBytes, crypto); | ||
| if (digest !== pointer.sha256) { | ||
| throw new ConfigCoreError('hash-mismatch', 'Snapshot SHA-256 does not match pointer'); | ||
| } | ||
| const value = parseDocument(rawBytes); |
There was a problem hiding this comment.
Freeze snapshot bytes before awaiting the digest
When a network adapter returns a pooled or otherwise reused Uint8Array, it can mutate the original buffer while the asynchronous SHA-256 operation hashes its internal copy; parsing then reads the mutated buffer, so bytes different from those covered by the signed pointer can be accepted as the snapshot. Copy the input once at function entry and use that immutable copy for the size check, digest, parsing, and returned raw bytes.
Useful? React with 👍 / 👎.
| readonly salt: string; | ||
| readonly value: boolean; | ||
| } | ||
|
|
There was a problem hiding this comment.
Move the remote configuration contract into schema
These snapshot, pointer, and emergency-document interfaces define signed payloads exchanged with a remote endpoint, so they are business data contracts rather than product-agnostic utilities. Keeping their types and validators in @linkcode/common bypasses the repository's schema ownership boundary; move the contract to @linkcode/schema and leave only reusable runtime adapters here.
AGENTS.md reference: packages/foundation/common/AGENTS.md:L9-L10
Useful? React with 👍 / 👎.
| @@ -0,0 +1,795 @@ | |||
| { | |||
There was a problem hiding this comment.
Exclude the byte-locked fixture from format checks
This newly added fixture is intentionally not Biome-formatted, but it remains in the formatter's input, so the required pnpm check:ci command now fails at format:check on every run. Since reformatting would invalidate the golden bytes and digest, add a targeted formatter exclusion for this fixture instead.
AGENTS.md reference: AGENTS.md:L49-L49
Useful? React with 👍 / 👎.
| "private": true, | ||
| "type": "module", | ||
| "exports": { | ||
| "./config": "./src/config/index.ts", |
There was a problem hiding this comment.
Split this commit below the 400-line hard limit
This commit introduces 3,103 lines even after excluding the golden fixture, spanning the contract, parser, persistence, state machine, and tests. That exceeds the repository's 400-line hard limit by several times and prevents the required atomic review history; split these concerns into independently compilable commits.
AGENTS.md reference: AGENTS.md:L48-L48
Useful? React with 👍 / 👎.
| const cloned: Record<string, JsonValue> = {}; | ||
| for (const [key, entry] of Object.entries(value)) cloned[key] = cloneJson(entry); |
There was a problem hiding this comment.
Preserve
__proto__ as an own JSON member
When a valid JSON object contains an own __proto__ property, assigning it into {} invokes the legacy prototype setter instead of creating an own member. The clone therefore changes signed/default configuration data and may expose the nested fields through inheritance; construct JSON records with data-property semantics, such as a null-prototype object or Object.fromEntries.
Useful? React with 👍 / 👎.
| const disabled = parseKnownValue(definition.parse, false, `disabled.${key}`); | ||
| if (disabled !== false) { |
There was a problem hiding this comment.
Validate every feature value as boolean
For a feature.* definition with a permissive parser such as an identity parser, this check only proves that false remains false; a numeric default or object-valued snapshot still passes and reaches consumers despite the stated feature-boolean invariant. Validate the parsed default and every parsed remote value as booleans, not merely the result of parsing the emergency sentinel.
Useful? React with 👍 / 👎.
Summary
@linkcode/common/configcore with typed definitions/access and injectable network, storage, SHA-256, Ed25519, and UUID boundariesValidation
pnpm exec tsc --build --noEmit packages/foundation/common/tsconfig.jsonpnpm typecheckpnpm test packages/foundation/common/src/config— 3 files, 37 tests passedpnpm test— 307 files passed, 1 skipped; 2,476 tests passed, 1 skippedNODE_OPTIONS=--max-old-space-size=8192 pnpm lint:ci— 0 errors (379 existing warnings)biome checkfor all editable CODE-543 TypeScript/package filesgit diff --checkFormat fixture exception
The unmodified root
pnpm format:checkreports only that Biome would reflow arrays in the cloud-owned golden fixture. The fixture is intentionally preserved exactly at 41,279 bytes with SHA-256d4f1749ed529b400610158fe320af5d3072cda3a168f02a8115da7cf1672b2c4; it was not rewritten and no repository-wide Biome exclusion was added.This PR provides the shared core and conformance coverage only; device runtime wiring is outside CODE-543.