Skip to content

feat(kernel-utils): narrowInterfaceGuard - #1051

Closed
ci-belphegor wants to merge 1 commit into
grypez/narrowing-4-e2e-testfrom
grypez/narrowing-5-narrow-interface-guard
Closed

ci-belphegor wants to merge 1 commit into
grypez/narrowing-4-e2e-testfrom
grypez/narrowing-5-narrow-interface-guard

Conversation

@ci-belphegor

@ci-belphegor ci-belphegor commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

The algebraic heart of narrowing, and the PR that most deserves scrutiny — hence deliberately free of exos, promises, and provenance. A pure narrowInterfaceGuard({ name, baseGuard, delta }) => InterfaceGuard that conjoins each delta pattern onto the corresponding argument position, inherits arity, optional and rest positions and return guards verbatim, drops methods the delta does not name, and asyncifies every method guard.

Position i addresses the base's guard at i walking required arguments, then optionals, then the rest guard, and stays in whichever category it lands in. A delta cannot promote an optional to required and cannot change arity.

Dropping unlisted methods makes the safe outcome the default: forgetting a method removes authority rather than granting it.

narrowInterfaceGuard is not exported: narrow is its only caller, so it stays internal to kernel-utils and this PR carries no changelog entry (labelled no-changelog).

Notes for reviewers

A position landing in the rest guard conjoins onto that one guard, and therefore constrains every trailing argument rather than only the position named — a rest guard is a single pattern, so per-position narrowing is unrepresentable there without changing arity. It stays ⊆ the base, and the surprise runs in the safe direction: the author gets less authority than intended, never more. Tested, and specified in the design doc.

An empty delta must be a no-op, not a narrowing. { readFile: [] } is defined as keeping a method entirely unchanged, so the claim soundness needs is ⊆, not ⊂.

The two "method not in methodGuards" errors are split on defaultGuards, which is a seam rather than a stylistic choice: a strict interface has defaultGuards: undefined, so the method genuinely does not exist, whereas a 'passable' interface admits it and merely guards it by default. PR 8 replaces only the second arm.

getGuardAt is deliberately not reused here. It maps a position to a guard, but narrowing has to write back into the category the position landed in; threading it through would have forced a non-null assertion or an unreachable undefined branch. Mapping over the base's own argGuards/optionalArgGuards makes the category boundary the loop bound, so it is the same walk with no duplicated logic.

Unmarks no ratchet cases.

Stack

PR 5 of 12. Base: #1050.

@ci-belphegor
ci-belphegor force-pushed the grypez/narrowing-5-narrow-interface-guard branch from 64369a0 to 810752b Compare September 11, 2026 11:42
@ci-belphegor
ci-belphegor added this pull request to stack #1060 September 11, 2026 11:44
@ci-belphegor
ci-belphegor force-pushed the grypez/narrowing-5-narrow-interface-guard branch from 810752b to 217d124 Compare September 29, 2026 17:36
@ci-belphegor ci-belphegor added the no-changelog Indicates that no changelog updates are required, and that related CI checks should be skipped. label Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 73.26%
⬇️ -0.07%
9998 / 13646
🔵 Statements 73.03%
⬇️ -0.09%
10127 / 13866
🔵 Functions 73.46%
⬇️ -0.29%
2342 / 3188
🔵 Branches 67.78%
⬆️ +0.09%
4126 / 6087
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/kernel-utils/src/index.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/kernel-utils/src/narrow-interface-guard.ts 100% 100% 100% 100%
packages/kernel-utils/src/narrowing.ts 100% 100% 100% 100%
Generated in workflow #5066 for commit 9ee7180 by the Vitest Coverage Report Action

@ci-belphegor
ci-belphegor force-pushed the grypez/narrowing-5-narrow-interface-guard branch from 217d124 to ef85f47 Compare September 30, 2026 13:44
@ci-belphegor
ci-belphegor force-pushed the grypez/narrowing-5-narrow-interface-guard branch from ef85f47 to b70cc93 Compare September 30, 2026 16:18
@ci-belphegor
ci-belphegor removed this pull request from stack #1060 September 30, 2026 16:44
@ci-belphegor
ci-belphegor added this pull request to stack #1130 September 30, 2026 16:45
Derive the interface guard of a narrowing: conjoin each delta pattern onto
the base's guard at the argument position it addresses, inherit arity, the
required/optional/rest split, and return guards verbatim, drop methods the
delta does not name, and asyncify every method guard for forwarding.

The guard is constructed as a conjunction with the base's own rather than
checked against it, so it admits no call the base does not. That is the
precondition join needs to disjoin two deltas without a pattern subtyping
decision procedure.

A delta naming a method the base guards by default still throws; PR-8
relaxes that arm into synthesizing a guard from the delta.

No exos, promises, or provenance — narrow wraps this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ci-belphegor
ci-belphegor force-pushed the grypez/narrowing-5-narrow-interface-guard branch from b70cc93 to 9ee7180 Compare October 1, 2026 18:38
@ci-belphegor

Copy link
Copy Markdown
Contributor Author

Superseded by #1134, which lands the narrowing library as one PR with no stubs. This PR's change is kept as a commit there for review.

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

Labels

no-changelog Indicates that no changelog updates are required, and that related CI checks should be skipped.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant