Skip to content

Close coordinate-backed Optics path#111

Open
flyingrobots wants to merge 4 commits into
mainfrom
v18-coordinate-optics-closeout
Open

Close coordinate-backed Optics path#111
flyingrobots wants to merge 4 commits into
mainfrom
v18-coordinate-optics-closeout

Conversation

@flyingrobots
Copy link
Copy Markdown
Member

@flyingrobots flyingrobots commented May 27, 2026

Summary

  • add the public coordinate-backed Optics path with prepareOpticBasis(), coordinate(), and coordinate.optic()
  • pin coordinate optic reads to checkpoint-tail evidence and captured frontier
  • add public conformance coverage for success, tail evidence, coordinate stability, absence semantics, blank targets, and missing-basis recovery
  • update README, API reference, Readings & Optics, migration docs, release notes, changelog, BEARING, and v18 backlog status

Verification

  • npm run typecheck:src
  • npm run typecheck:test
  • npm run typecheck:consumer
  • npm run lint
  • npm run lint:md
  • npm run lint:md:code
  • npm run lint:sludge
  • npm run lint:quarantine-graduate
  • npm run typecheck:policy
  • npm run lint:semgrep
  • npm run typecheck:surface
  • npx vitest run test/conformance/v18CoordinateOpticPublicPath.test.ts test/unit/index.exports.test.ts test/unit/domain/index.exports.test.ts test/unit/domain/WarpWorldline.test.ts test/unit/domain/types/WorldlineSelector.test.ts
  • npm run test:local
  • pre-push IRONCLAD M9 gate passed, including 527 test files and 7163 tests

Summary by CodeRabbit

  • New Features

    • Introduced coordinate-backed Optics enabling coherent node and property reads using prepareOpticBasis(), coordinate(), and coordinate.optic() methods.
  • Documentation

    • Updated API reference, migration guides, release notes, and design specifications for the new coordinate Optics workflow and usage patterns.
  • Tests

    • Added conformance test suite validating coordinate Optics behavior and error handling; extended type-checking coverage for new coordinate features.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

📝 Walkthrough

Walkthrough

This PR lands the v18 Optics public API closeout, enabling coordinate-backed coherent optic reads through a stable causal position without materializing the full graph. New WarpWorldline.prepareOpticBasis() and coordinate() methods anchor the public workflow, pinning checkpoint identity and writer frontier evidence for repeatable multi-read behavior across worldline advancement.

Changes

v18 Optics Public API Closeout: Coordinate-Backed Coherent Reads

Layer / File(s) Summary
Domain Models: Coordinate & Optic Basis Value Objects
src/domain/WarpWorldlineOpticBasis.ts, src/domain/WarpWorldlineCoordinate.ts, index.ts
New frozen immutable value objects: WarpWorldlineOpticBasis validates and stores checkpoint identity; WarpWorldlineCoordinate freezes/sorts frontier entries and exposes frontier(), source(), and optic() methods. Both throw WarpError on invalid inputs. Public type exports added to barrel.
WarpWorldline Entry Points: prepareOpticBasis() & coordinate()
src/domain/WarpWorldline.ts
WarpWorldline adds two new async methods: prepareOpticBasis() materializes graph and caches basis (throws WarpError if unavailable), coordinate() reads frontier callback and constructs WarpWorldlineCoordinate (throws QueryError with context if basis missing). openWarpWorldline wiring updated to use openRuntimeHostProduct and supply coordinate support callbacks.
Coordinate Selector & WorldlineSource Pinning
src/domain/types/CoordinateSelector.ts, src/domain/types/WorldlineSelector.ts, src/domain/capabilities/QueryCapability.ts
CoordinateSelector extended with optional checkpointSha parameter; new validateCheckpointSha() helper validates field (throws QueryError on invalid). clone() and toDTO() preserve/serialize checkpointSha. WorldlineSelector.fromPlainObject() updated to pass three args when constructing coordinate selectors. WorldlineSource coordinate union reformatted (no semantic change).
Optic Source Coordination: Checkpoint SHA & Patch Loading Delegation
src/domain/services/optic/CoordinateCheckpointTailOpticSource.ts, src/domain/services/optic/CheckpointTailOpticSource.ts, src/domain/services/Worldline.ts
New CoordinateCheckpointTailOpticSource wraps checkpoint SHA and frozen frontier; returns fixed checkpoint via _readCheckpointSha(), resolves writer tips from frontier, delegates patch loading to wrapped source. Worldline.optic() branches: live selectors use _opticSource; coordinate selectors wrap source in CoordinateCheckpointTailOpticSource (validates checkpoint SHA present, throws E_OPTIC_NO_BOUNDED_BASIS if missing); other kinds throw error. CheckpointTailOpticSource abstract methods added for checkpoint SHA reading and patch chain loading.
Checkpoint & Persistence Layer: SHA Reading & Patch Delegation
src/domain/services/controllers/CheckpointController.ts, src/domain/services/optic/CheckpointTailBasisLoader.ts, src/domain/RuntimeHost.ts, src/domain/warp/RuntimeHostProduct.ts, src/domain/services/controllers/QueryController.ts
CheckpointController._readCheckpointSha() reads checkpoint SHA from persistence. CheckpointTailBasisLoader delegates SHA retrieval to optic source instead of building ref locally. RuntimeHost exposes delegation method forwarding to controller. RuntimeHostProduct type declares two new methods: _readCheckpointSha() and _loadPatchChainFromSha(). QueryController.hasWorldlineOpticSource tightened to require both new capabilities.
Tests & Validation
test/conformance/v18CoordinateOpticPublicPath.test.ts, test/type-check/consumer.ts, test/unit/index.exports.test.ts, test/unit/scripts/v18-worldline-api-doc-guard.test.ts
New conformance suite validates five behavioral guarantees: node liveness and property reads via prepared basis, tail evidence folding, snapshot stability across worldline advancement, absence semantics (alive=false, exists=false for missing entries), blank identifiers as absent. Error test asserts coordinate() without prepared basis rejects with E_OPTIC_NO_BOUNDED_BASIS. Type-check surface expanded with WarpWorldlineCoordinate, WarpWorldlineOpticBasis, and frontier entry type; smoke test extended with optic basis/coordinate/read operations. Export assertions and API documentation guard updated.
Documentation, API Reference, Migration Guides & Release Management
CHANGELOG.md, README.md, docs/API_REFERENCE.md, docs/BEARING.md, docs/READINGS_AND_OPTICS.md, docs/migrations/v18.0.0.md, docs/releases/v18.0.0/README.md, docs/design/0265-v18-optics-public-api-closeout/v18-optics-public-api-closeout.md, docs/method/backlog/*
Comprehensive documentation defining v18 Optics closeout story: changelog entry, README workflow docs, API reference for new methods and coherence behavior, READINGS_AND_OPTICS refocused to coordinate-based approach, BEARING clarifying Worldline-first pivot and release blockers, design PRD with user stories/acceptance criteria/test plan/delivery plan/release gates, migration guide updated to coordinate sequence, release notes highlighting feature, backlog metrics incremented, new API_optics-public-api-closeout card with completion checklist, release blockers document updated with evidence requirements.

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly Related PRs

  • git-stunts/git-warp#110: Both PRs change the v18 public WarpWorldline API surface—PR #110 introduces openWarpWorldline/WarpWorldline basics (including optic()), while this PR extends src/domain/WarpWorldline.ts to add prepareOpticBasis() and coordinate() support for coordinate-backed coherent optics.

Poem

🐰 A coordinate holds steady ground,
While the worldline spins around,
Now all reads from one pinned place,
Know their checkpoint time and space—
Coherence blooms without the fall,
Optics first, no graph at all! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Close coordinate-backed Optics path' clearly summarizes the primary change: completing the implementation of a coordinate-backed Optics API feature.
Description check ✅ Passed The description includes a clear Summary section with bullet points explaining the changes, a Verification section documenting comprehensive testing, and addresses the key technical aspects of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v18-coordinate-optics-closeout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Release Preflight

  • package version: 18.0.0
  • prerelease: false
  • npm dist-tag on release: latest
  • npm pack dry-run: passed
  • jsr publish dry-run: passed

If you tag this commit as v18.0.0, release workflow will publish.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/domain/services/optic/CheckpointTailBasisLoader.ts (1)

59-64: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Treat empty checkpoint SHA as missing at the boundary.

_readCheckpointSha() currently only rejects null. An empty SHA should also map to missing-checkpoint to avoid downstream opaque persistence failures.

Suggested patch
   private async _readCheckpointSha(): Promise<string> {
     const checkpointSha = await this._source._readCheckpointSha();
-    if (checkpointSha === null) {
+    if (checkpointSha === null || checkpointSha.length === 0) {
       throwNoBoundedBasis(this._source.graphName, 'missing-checkpoint');
     }
     return checkpointSha;
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/domain/services/optic/CheckpointTailBasisLoader.ts` around lines 59 - 64,
In _readCheckpointSha(), treat an empty string the same as null: after calling
this._source._readCheckpointSha(), check if checkpointSha is null or
checkpointSha === '' and if so call throwNoBoundedBasis(this._source.graphName,
'missing-checkpoint'); otherwise return the SHA; update the _readCheckpointSha
method (referencing this._source._readCheckpointSha, checkpointSha,
this._source.graphName, and throwNoBoundedBasis) so empty strings are mapped to
the missing-checkpoint boundary error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/domain/services/optic/CoordinateCheckpointTailOpticSource.ts`:
- Around line 27-38: The constructor currently trusts options.frontier and
fields on options.source and can throw raw TypeErrors; add defensive validation
at the start of the CoordinateCheckpointTailOpticSource constructor to assert
options.source exists and has required identity fields (graphName, _persistence,
_codec, _blobStorage, _commitMessageCodec) using assertNonEmpty where
appropriate, validate options.checkpointSha (already present) and validate
options.frontier is non-null and shape-compatible before calling copyFrontier;
replace raw errors by throwing a WarpError (with a clear message) if validation
fails, and wrap the copyFrontier call in a try/catch that converts unexpected
exceptions into a WarpError so the constructor always enforces invariants rather
than leaking TypeErrors.

In `@src/domain/services/Worldline.ts`:
- Around line 136-139: Update the thrown QueryError in the unsupported-selector
branch to use a clear, accurate message instead of "v17 foundation optics
support live worldlines only"; locate the throw new QueryError(...) with code
'E_OPTIC_NO_BOUNDED_BASIS' (inside the unsupported-selector branch that
references this._source.constructor.name) and change the error text to describe
the actual unsupported selector case (e.g., indicate that the selector type is
unsupported or must be a coordinate selector), keeping the same error code and
context payload.

In `@src/domain/types/CoordinateSelector.ts`:
- Around line 81-86: The validateCheckpointSha function currently accepts
strings that are only whitespace; update its validation in validateCheckpointSha
to first ensure checkpointSha is a string, then trim() it and reject if the
trimmed length is 0 (throw the same QueryError message), returning the trimmed
value (or null when input is null/undefined) so whitespace-only inputs are
treated as invalid and the selector invariant is preserved.

In `@src/domain/WarpWorldlineCoordinate.ts`:
- Around line 25-33: The constructor of WarpWorldlineCoordinate must validate
the frontier and createWorldline inputs up front: add explicit runtime checks in
the constructor for options.frontier to be a non-null object with an entries
array (or whatever shape freezeFrontier expects) and for options.createWorldline
to be either undefined or a function before calling freezeFrontier or assigning
to this._createWorldline; if validation fails throw a domain error (e.g.,
TypeError or a custom error) with a clear message. Locate the constructor in
class WarpWorldlineCoordinate and add these checks prior to calling
freezeFrontier(options.frontier) and before setting this._createWorldline so
invalid inputs fail fast and with a domain-style error. Ensure the checks mirror
the same validation you will add in the other constructor uses referenced around
the class (lines noted in the review) so all construction paths enforce the
invariants.

In `@src/domain/WarpWorldlineOpticBasis.ts`:
- Around line 22-24: The assertNonEmpty validator currently allows strings that
are only whitespace; update the function assertNonEmpty(value: string, field:
string) used by WarpWorldlineOpticBasis to treat whitespace-only values as empty
by checking value.trim().length === 0 (or using a regex) in addition to the
existing typeof check, and continue to throw WarpError(field + "...") when
validation fails so the constructor enforces the non-whitespace invariant for
identity fields.

---

Outside diff comments:
In `@src/domain/services/optic/CheckpointTailBasisLoader.ts`:
- Around line 59-64: In _readCheckpointSha(), treat an empty string the same as
null: after calling this._source._readCheckpointSha(), check if checkpointSha is
null or checkpointSha === '' and if so call
throwNoBoundedBasis(this._source.graphName, 'missing-checkpoint'); otherwise
return the SHA; update the _readCheckpointSha method (referencing
this._source._readCheckpointSha, checkpointSha, this._source.graphName, and
throwNoBoundedBasis) so empty strings are mapped to the missing-checkpoint
boundary error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b89ceb76-8bbb-4362-bb9b-ab2e0d793a17

📥 Commits

Reviewing files that changed from the base of the PR and between 7711bc0 and 7dce34c.

📒 Files selected for processing (31)
  • CHANGELOG.md
  • README.md
  • docs/API_REFERENCE.md
  • docs/BEARING.md
  • docs/READINGS_AND_OPTICS.md
  • docs/design/0265-v18-optics-public-api-closeout/v18-optics-public-api-closeout.md
  • docs/method/backlog/README.md
  • docs/method/backlog/v18.0.0/API_optics-public-api-closeout.md
  • docs/method/backlog/v18.0.0/README.md
  • docs/method/backlog/v18.0.0/RELEASE_v18-public-release-blockers.md
  • docs/migrations/v18.0.0.md
  • docs/releases/v18.0.0/README.md
  • index.ts
  • src/domain/RuntimeHost.ts
  • src/domain/WarpWorldline.ts
  • src/domain/WarpWorldlineCoordinate.ts
  • src/domain/WarpWorldlineOpticBasis.ts
  • src/domain/capabilities/QueryCapability.ts
  • src/domain/services/Worldline.ts
  • src/domain/services/controllers/CheckpointController.ts
  • src/domain/services/controllers/QueryController.ts
  • src/domain/services/optic/CheckpointTailBasisLoader.ts
  • src/domain/services/optic/CheckpointTailOpticSource.ts
  • src/domain/services/optic/CoordinateCheckpointTailOpticSource.ts
  • src/domain/types/CoordinateSelector.ts
  • src/domain/types/WorldlineSelector.ts
  • src/domain/warp/RuntimeHostProduct.ts
  • test/conformance/v18CoordinateOpticPublicPath.test.ts
  • test/type-check/consumer.ts
  • test/unit/index.exports.test.ts
  • test/unit/scripts/v18-worldline-api-doc-guard.test.ts

Comment on lines +27 to +38
constructor(options: CoordinateCheckpointTailOpticSourceOptions) {
super();
this.graphName = options.source.graphName;
this._persistence = options.source._persistence;
this._codec = options.source._codec;
this._blobStorage = options.source._blobStorage;
this._commitMessageCodec = options.source._commitMessageCodec;
this._source = options.source;
assertNonEmpty(options.checkpointSha, 'checkpointSha');
this._checkpointSha = options.checkpointSha;
this._frontier = copyFrontier(options.frontier);
Object.freeze(this);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add defensive constructor validation for frontier and identity fields.

With malformed runtime input, this path can currently throw raw TypeErrors instead of a WarpError at the boundary.

Suggested fix
   constructor(options: CoordinateCheckpointTailOpticSourceOptions) {
     super();
@@
+    if (!(options.frontier instanceof Map)) {
+      throw new WarpError(
+        'Coordinate checkpoint-tail optic source requires a frontier Map',
+        'E_COORDINATE_CHECKPOINT_TAIL_OPTIC_SOURCE',
+        { context: { field: 'frontier' } },
+      );
+    }
     assertNonEmpty(options.checkpointSha, 'checkpointSha');
@@
 function assertNonEmpty(value: string, field: string): void {
-  if (value.length === 0) {
+  if (typeof value !== 'string' || value.trim().length === 0) {
     throw new WarpError(

As per coding guidelines, "Validate at boundaries and constructors; constructors establish invariants and must not perform I/O."

Also applies to: 76-80, 88-90

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/domain/services/optic/CoordinateCheckpointTailOpticSource.ts` around
lines 27 - 38, The constructor currently trusts options.frontier and fields on
options.source and can throw raw TypeErrors; add defensive validation at the
start of the CoordinateCheckpointTailOpticSource constructor to assert
options.source exists and has required identity fields (graphName, _persistence,
_codec, _blobStorage, _commitMessageCodec) using assertNonEmpty where
appropriate, validate options.checkpointSha (already present) and validate
options.frontier is non-null and shape-compatible before calling copyFrontier;
replace raw errors by throwing a WarpError (with a clear message) if validation
fails, and wrap the copyFrontier call in a try/catch that converts unexpected
exceptions into a WarpError so the constructor always enforces invariants rather
than leaking TypeErrors.

Comment on lines +136 to +139
throw new QueryError('v17 foundation optics support live worldlines only', {
code: 'E_OPTIC_NO_BOUNDED_BASIS',
context: { selector: this._source.constructor.name },
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix stale error text in unsupported-selector branch.

This now supports coordinate selectors, but the message still says “live worldlines only,” which is misleading during error handling/debugging.

Suggested patch
-    throw new QueryError('v17 foundation optics support live worldlines only', {
+    throw new QueryError('v17 foundation optics support live and coordinate worldlines only', {
       code: 'E_OPTIC_NO_BOUNDED_BASIS',
       context: { selector: this._source.constructor.name },
     });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/domain/services/Worldline.ts` around lines 136 - 139, Update the thrown
QueryError in the unsupported-selector branch to use a clear, accurate message
instead of "v17 foundation optics support live worldlines only"; locate the
throw new QueryError(...) with code 'E_OPTIC_NO_BOUNDED_BASIS' (inside the
unsupported-selector branch that references this._source.constructor.name) and
change the error text to describe the actual unsupported selector case (e.g.,
indicate that the selector type is unsupported or must be a coordinate
selector), keeping the same error code and context payload.

Comment on lines +81 to +86
function validateCheckpointSha(checkpointSha: string | null | undefined): string | null {
if (checkpointSha === undefined || checkpointSha === null) {
return null;
}
if (typeof checkpointSha !== 'string' || checkpointSha.length === 0) {
throw new QueryError('checkpointSha must be a non-empty string when provided', {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Tighten checkpointSha validation to reject whitespace-only values.

Current validation allows " " which weakens selector invariants.

Suggested fix
-  if (typeof checkpointSha !== 'string' || checkpointSha.length === 0) {
+  if (typeof checkpointSha !== 'string' || checkpointSha.trim().length === 0) {
     throw new QueryError('checkpointSha must be a non-empty string when provided', {

As per coding guidelines, "Validate at boundaries and constructors; constructors establish invariants and must not perform I/O."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/domain/types/CoordinateSelector.ts` around lines 81 - 86, The
validateCheckpointSha function currently accepts strings that are only
whitespace; update its validation in validateCheckpointSha to first ensure
checkpointSha is a string, then trim() it and reject if the trimmed length is 0
(throw the same QueryError message), returning the trimmed value (or null when
input is null/undefined) so whitespace-only inputs are treated as invalid and
the selector invariant is preserved.

Comment on lines +25 to +33
constructor(options: WarpWorldlineCoordinateOptions) {
assertNonEmpty(options.worldlineName, 'worldlineName');
assertNonEmpty(options.checkpointSha, 'checkpointSha');
this.worldlineName = options.worldlineName;
this.checkpointSha = options.checkpointSha;
this.frontierEntries = freezeFrontier(options.frontier);
this._createWorldline = options.createWorldline;
Object.freeze(this);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Harden constructor boundary checks for frontier and createWorldline.

Invalid runtime input currently fails later with raw TypeErrors (frontier.entries / calling non-function) instead of a domain error at construction time.

Suggested fix
   constructor(options: WarpWorldlineCoordinateOptions) {
+    if (!(options.frontier instanceof Map)) {
+      throw new WarpError(
+        'WarpWorldline coordinate requires a frontier Map',
+        'E_WARP_WORLDLINE_COORDINATE',
+        { context: { field: 'frontier' } },
+      );
+    }
+    if (typeof options.createWorldline !== 'function') {
+      throw new WarpError(
+        'WarpWorldline coordinate requires a createWorldline function',
+        'E_WARP_WORLDLINE_COORDINATE',
+        { context: { field: 'createWorldline' } },
+      );
+    }
     assertNonEmpty(options.worldlineName, 'worldlineName');
     assertNonEmpty(options.checkpointSha, 'checkpointSha');
@@
 function assertNonEmpty(value: string, field: string): void {
-  if (typeof value !== 'string' || value.length === 0) {
+  if (typeof value !== 'string' || value.trim().length === 0) {
     throw new WarpError(

As per coding guidelines, "Validate at boundaries and constructors; constructors establish invariants and must not perform I/O."

Also applies to: 52-54, 66-68

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/domain/WarpWorldlineCoordinate.ts` around lines 25 - 33, The constructor
of WarpWorldlineCoordinate must validate the frontier and createWorldline inputs
up front: add explicit runtime checks in the constructor for options.frontier to
be a non-null object with an entries array (or whatever shape freezeFrontier
expects) and for options.createWorldline to be either undefined or a function
before calling freezeFrontier or assigning to this._createWorldline; if
validation fails throw a domain error (e.g., TypeError or a custom error) with a
clear message. Locate the constructor in class WarpWorldlineCoordinate and add
these checks prior to calling freezeFrontier(options.frontier) and before
setting this._createWorldline so invalid inputs fail fast and with a
domain-style error. Ensure the checks mirror the same validation you will add in
the other constructor uses referenced around the class (lines noted in the
review) so all construction paths enforce the invariants.

Comment on lines +22 to +24
function assertNonEmpty(value: string, field: string): void {
if (typeof value !== 'string' || value.length === 0) {
throw new WarpError(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Reject whitespace-only identity values in constructor validation.

assertNonEmpty currently accepts " ", which allows invalid identity fields into this value object.

Suggested fix
 function assertNonEmpty(value: string, field: string): void {
-  if (typeof value !== 'string' || value.length === 0) {
+  if (typeof value !== 'string' || value.trim().length === 0) {
     throw new WarpError(

As per coding guidelines, "Validate at boundaries and constructors; constructors establish invariants and must not perform I/O."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function assertNonEmpty(value: string, field: string): void {
if (typeof value !== 'string' || value.length === 0) {
throw new WarpError(
function assertNonEmpty(value: string, field: string): void {
if (typeof value !== 'string' || value.trim().length === 0) {
throw new WarpError(
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/domain/WarpWorldlineOpticBasis.ts` around lines 22 - 24, The
assertNonEmpty validator currently allows strings that are only whitespace;
update the function assertNonEmpty(value: string, field: string) used by
WarpWorldlineOpticBasis to treat whitespace-only values as empty by checking
value.trim().length === 0 (or using a regex) in addition to the existing typeof
check, and continue to throw WarpError(field + "...") when validation fails so
the constructor enforces the non-whitespace invariant for identity fields.

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