Skip to content

feat(contract): Relayfile Path Contract v1 — grammar, fixtures, Go conformance runners#357

Merged
khaliqgant merged 2 commits into
mainfrom
contract/path-grammar-v1
Jul 18, 2026
Merged

feat(contract): Relayfile Path Contract v1 — grammar, fixtures, Go conformance runners#357
khaliqgant merged 2 commits into
mainfrom
contract/path-grammar-v1

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

Phase 1 of the path-contract stabilization plan (cloud/specs/relayfile-path-contract-stabilization.md). Per the operator ruling (2026-07-18), this repo owns the path contract; this PR documents and fences the grammar exactly as internal/httpapi/auth.go already enforces it. No runtime verdict changes — the fixture suite passes against unmodified enforcement code.

  • contract/README.md — the authoritative v1 grammar: canonical file paths, normalization (quirks pinned + flagged), scope grammar (plane:resource:action[:path]), suffix-glob matching semantics, grant-set matching incl. narrow-grant precedence, containment, and mounts_at derivation. Mid-path segment globs are invalid: relayfile:fs:read:/github/repos/*/*/issues/** (the scope hosted cloud emits today) authorizes nothing under the contract.
  • contract/fixtures/*.json — language-neutral conformance fixtures (path-normalization, containment, scope-paths, auth-matching; 58 cases). Invalid scope paths assert valid: false and carry probe_files that must not match — so an implementation whose matcher accepts a mid-path glob fails the suite even if it skips validity checks. The live hosted/OSS divergence case is pinned verbatim.
  • internal/httpapi/path_contract.go — reference scopePathValid / scopePathMountRoot (grammar codification only).
  • Fixture runners in internal/httpapi and internal/relayfile execute the fixtures against the real scopeMatchesPath / scopePathMatches / normalizePath / withinBase.
  • make contract-test — named entry point; the suite also runs under plain go test ./..., so ci.yml / contract.yml already gate it.

Also includes the Phase 1 audit of packages/local-mount/src/mount.ts (README Appendix A): it holds three local-path theories (gitignore globs, ExcludeRules, normalizeRelativePosix) but never touches scope paths — no authorization exposure; the risk is vocabulary drift, flagged.

Prior art: cloud#989 (HTTP-level contract-test spec) — that suite remains the layer above; this PR is the path-vocabulary layer it depends on.

Phase 2 consumers

relayfile-cloud, relayauth, relayfile-adapters, cloud run these fixtures and report divergence (expected red: relayfile-cloud too permissive, cloud emits invalid scopes). No fixture may be edited to make an implementation pass.

Test plan

  • make contract-test — green (60 httpapi subtests, 26 relayfile subtests)
  • go test ./internal/httpapi ./internal/relayfile — green
  • go vet ./internal/... — clean

🤖 Generated with Claude Code

Review in cubic

…onformance runners

Phase 1 of the path-contract stabilization plan
(cloud/specs/relayfile-path-contract-stabilization.md): document and fence
the scope-path grammar exactly as internal/httpapi/auth.go enforces it —
suffix globs only, mid-path segment globs invalid.

- contract/README.md: authoritative v1 grammar (canonical paths,
  normalization, scope grammar, glob matching, containment, mounts_at),
  flagged in-repo divergences, and the packages/local-mount/src/mount.ts
  path-theory audit (Appendix A).
- contract/fixtures/*.json: language-neutral conformance fixtures.
  Invalid scope paths (incl. /github/repos/*/*/issues/**, the live
  hosted/OSS divergence) assert valid:false AND carry probe_files that
  must not match — an implementation that accepts a mid-path glob fails
  the suite even without a validity check.
- internal/httpapi/path_contract.go: reference scopePathValid /
  scopePathMountRoot (grammar codification; no runtime verdict changes).
- Fixture runners in internal/httpapi and internal/relayfile against the
  real scopeMatchesPath / scopePathMatches / normalizePath / withinBase.
- make contract-test: named entry point (also runs under go test ./...,
  so existing ci.yml/contract.yml already gate it).

Prior art: cloud#989 (HTTP-level contract suite; this is the
path-vocabulary layer beneath it).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@khaliqgant, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 617fa558-a7fc-467a-bdba-ab2243a89ef4

📥 Commits

Reviewing files that changed from the base of the PR and between 5f1d6c6 and bef155d.

📒 Files selected for processing (9)
  • Makefile
  • contract/README.md
  • contract/fixtures/auth-matching.json
  • contract/fixtures/containment.json
  • contract/fixtures/path-normalization.json
  • contract/fixtures/scope-paths.json
  • internal/httpapi/contract_fixtures_test.go
  • internal/httpapi/path_contract.go
  • internal/relayfile/contract_fixtures_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch contract/path-grammar-v1

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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces the Relayfile Path Contract v1, which defines path syntax, normalization, containment, scope-glob matching, and mount-root derivation. It adds language-neutral JSON fixtures, corresponding Go test runners, and a reference implementation for scope path validation and mount-root derivation. Feedback suggests adding a defensive check in scopePathMountRoot when slicing the prefix string to prevent potential panics if validation logic is bypassed or modified in the future.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +64 to +66
case strings.HasSuffix(scopePath, "*"):
prefix := strings.TrimSuffix(scopePath, "*")
return orRoot(prefix[:strings.LastIndex(prefix, "/")]), true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To prevent potential panics and adhere to defensive programming practices, it is safer to check if strings.LastIndex returns -1 before slicing the prefix string. Although scopePathValid currently guarantees that scopePath starts with / (and thus prefix contains at least one /), adding this check makes the code more robust against future changes or bypasses of the validation logic.

	case strings.HasSuffix(scopePath, "*"):
		prefix := strings.TrimSuffix(scopePath, "*")
		idx := strings.LastIndex(prefix, "/")
		if idx == -1 {
			return "/", true
		}
		return orRoot(prefix[:idx]), true

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown

Relayfile Eval Review

Run: .relayfile/evals/runs/2026-07-18T14-09-34-721Z-HEAD-provider
Mode: provider
Git SHA: ed03273

Passed: 4 | Needs human: 0 | Reviewable: 0 | Missing output: 0 | Failed: 0 | Skipped: 0

Human Review Cases

No reviewable human-review cases captured Relayfile output.

@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: 01f3fb9297

ℹ️ 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 thread contract/README.md
Comment on lines +54 to +55
6. is compared **byte-exact and case-sensitive**. No Unicode normalization,
no percent-decoding at this layer (transport decoding happens before the

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 Align canonical whitespace with authorization matching

Canonical paths may currently end in whitespace because the grammar permits any non-/ byte, yet scopeMatchesPath applies strings.TrimSpace before authorization while normalizePath preserves that whitespace as part of the stored key. Consequently, an exact grant for /public also authorizes a distinct file such as /public on the file routes, contradicting the byte-exact guarantee here. Exclude trim-space boundaries from canonical paths or change the matching rule, and add a collision fixture rather than only testing harmless padding around a path.

Useful? React with 👍 / 👎.

Review finding on #357: "/" was declared valid with mounts_at "/" but no
fixture pinned that it authorizes only the root node itself — the same
valid-but-authorizes-nothing failure class the contract exists to
eliminate. Adds root-scope-path-* auth-matching cases (exact-node match
only; everything beneath root denied), a §5.1 note on the asymmetry, and
a "stricter subsets" section: producers may accept a documented subset of
the grammar, enforcers must implement all of it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@khaliqgant

Copy link
Copy Markdown
Member Author

Review addressed in bef155d: added root-scope-path-matches-only-root-node / root-scope-path-denies-everything-beneath-root auth-matching fixtures pinning that / is an exact-node grant (verified against unmodified scopePathMatches: equality only — no glob branch fires), a §5.1 note on the / vs * asymmetry, and a "Stricter subsets" section making producer-side subsets (e.g. the cloud canonicalizer's terminal-/**-only rule) a declared choice while enforcers must implement the full grammar. Kept / valid — making it invalid is a semantic change, deferred per the review. Phase 0(b) is in flight in parallel (deployed-spec DB audit via workflow_dispatch, cloud repo).

@khaliqgant
khaliqgant merged commit f1a30b2 into main Jul 18, 2026
10 checks passed
@khaliqgant
khaliqgant deleted the contract/path-grammar-v1 branch July 18, 2026 14:35
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