Skip to content

feat(config): add shared configuration core - #404

Open
AprilNEA wants to merge 2 commits into
xuan/code-537from
xuan/code-543
Open

feat(config): add shared configuration core#404
AprilNEA wants to merge 2 commits into
xuan/code-537from
xuan/code-543

Conversation

@AprilNEA

@AprilNEA AprilNEA commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

  • add a platform-independent @linkcode/common/config core with typed definitions/access and injectable network, storage, SHA-256, Ed25519, and UUID boundaries
  • verify signed pointers and emergency documents from exact raw bytes, preserve unknown signed-envelope root fields for JCS, enforce immutable targets and canonical uint64 replay/equivocation rules, and persist replay high-water independently of cached signed bytes
  • implement ETag/304 retry, raw snapshot size/hash verification, LKG/default/remote recovery, RFC 7386 per-key overrides, restricted SemVer conditions, MurmurHash3 rollout, hot/cold projection, and independent fail-open emergency state
  • consume the cloud-owned golden contract fixture byte-for-byte as conformance coverage while retaining the CODE-537 signing POC

Validation

  • pnpm exec tsc --build --noEmit packages/foundation/common/tsconfig.json
  • pnpm typecheck
  • pnpm test packages/foundation/common/src/config — 3 files, 37 tests passed
  • pnpm test — 307 files passed, 1 skipped; 2,476 tests passed, 1 skipped
  • NODE_OPTIONS=--max-old-space-size=8192 pnpm lint:ci — 0 errors (379 existing warnings)
  • targeted biome check for all editable CODE-543 TypeScript/package files
  • git diff --check

Format fixture exception

The unmodified root pnpm format:check reports only that Biome would reflow arrays in the cloud-owned golden fixture. The fixture is intentionally preserved exactly at 41,279 bytes with SHA-256 d4f1749ed529b400610158fe320af5d3072cda3a168f02a8115da7cf1672b2c4; 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.

@linear-code

linear-code Bot commented Aug 3, 2026

Copy link
Copy Markdown

CODE-543

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +103 to +107
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 @@
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +50 to +51
const cloned: Record<string, JsonValue> = {};
for (const [key, entry] of Object.entries(value)) cloned[key] = cloneJson(entry);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +31 to +32
const disabled = parseKnownValue(definition.parse, false, `disabled.${key}`);
if (disabled !== false) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant