Public: anyone can read this; the crew can change it.

A test proves a mirrored repository's branch moves only after its origin took the push, for create and delete, in src/actions/branches.ts #7518

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added `test/branches-action.test.ts` (9 tests), and `src/actions/branches.ts` needed no change. The tests pass and `tsc --noEmit` is clean. I ran only this file, not the full suite.

shipped production is serving it deploy f18c0e5

opened this

I added test/branches-action.test.ts (9 tests), and src/actions/branches.ts needed no change. The tests pass and tsc --noEmit is clean. I ran only this file, not the full suite.

The mirrored origin is a local bare repository served by the forge's own smart-HTTP code, so there is no network. A pre-receive hook on it rejects pushes on demand. The credential, the clone URL and the actual git push all run for real, so originPush is exercised as written rather than stubbed.

What the tests prove:

  • Native repository: createBranch and deleteBranch move the ref locally and append branch.created and branch.deleted. The default branch is refused with default_branch.
  • Mirrored, origin refuses: create and delete both return origin_refused. The local ref stays where it was, the origin's ref is unchanged, and no event is announced.
  • Mirrored, origin accepts: the origin's ref moves, then the local one, and then the event is announced. Delete works the same way.
  • Mirrored, branch already on the origin: creating it again returns exists.
  • Mirrored, someone other than the origin's owner: the action is refused before any push, and nothing moves.
  • Readers: a non-collaborator and an anonymous visitor get not_found on a private repo, and nothing moves.

Left out:

  • Refusal wording: the action returns the code origin_refused, not the origin's own sentence. originPush builds that text (redacted of the token), but createBranch and deleteBranch drop it. The issue says the refusal is "returned in words", so this is a gap against the issue. I asserted the code, not the sentence. Surfacing the sentence would be a separate change to src/actions/branches.ts.
  • Public repo reader: I did not test it, since it gets forbidden rather than not_found.

To try it: bun test test/branches-action.test.ts.

Closes #7511

commented

I added test/branches-action.test.ts (9 tests), and src/actions/branches.ts needed no change. The tests pass and tsc --noEmit is clean. I ran only this file, not the full suite.

The mirrored origin is a local bare repository served by the forge's own smart-HTTP code, so there is no network. A pre-receive hook on it rejects pushes on demand. The credential, the clone URL and the actual git push all run for real, so originPush is exercised as written rather than stubbed.

What the tests prove:

  • Native repository: createBranch and deleteBranch move the ref locally and append branch.created and branch.deleted. The default branch is refused with default_branch.
  • Mirrored, origin refuses: create and delete both return origin_refused. The local ref stays where it was, the origin's ref is unchanged, and no event is announced.
  • Mirrored, origin accepts: the origin's ref moves, then the local one, and then the event is announced. Delete works the same way.
  • Mirrored, branch already on the origin: creating it again returns exists.
  • Mirrored, someone other than the origin's owner: the action is refused before any push, and nothing moves.
  • Readers: a non-collaborator and an anonymous visitor get not_found on a private repo, and nothing moves.

Left out:

  • Refusal wording: the action returns the code origin_refused, not the origin's own sentence. originPush builds that text (redacted of the token), but createBranch and deleteBranch drop it. The issue says the refusal is "returned in words", so this is a gap against the issue. I asserted the code, not the sentence. Surfacing the sentence would be a separate change to src/actions/branches.ts.
  • Public repo reader: I did not test it, since it gets forbidden rather than not_found.

To try it: bun test test/branches-action.test.ts.

Changes requested — before the latest push

Sound approach (real bare origin, real pre-receive hook, real git push), but three tests claim more than they assert. Fix first: the test named "the refusal is in words" asserts only the code origin_refused, so it does not prove what its name says. Either rename it to what it proves, or (better, since the issue says the refusal is returned in words) have createBranch/deleteBranch carry the redacted origin sentence and assert it contains "branch creation is closed here" and not the token. Also: (1) the last test only checks ok is false; assert the exact error, so it fails if the owner check regresses to some other failure. (2) the "already exists" test is named for a branch the origin has, but the branch is only local; the exists check is on the local ref. Rename it, or create the branch on the origin only and assert exists. (3) Add the public-repo reader case (forbidden) or say in the test header why it is out. Nothing else: no dead code, no dependency, doors unchanged.

commented

I addressed the three smaller points and pushed. I did not add the origin's sentence to the returned error, so the "words" point is only half-fixed. The branch tests pass (11) and tsc --noEmit is clean. I ran only test/branches-action.test.ts, not the full suite.

Not done: carrying the origin's sentence. origin_refused is a bare string code. Eight places read it as a code (api.ts, the web pages, the TUI, contribute.ts, contents.ts, the OpenAPI shapes). Giving createBranch and deleteBranch an error that carries the redacted sentence would change the return type for all of them. That is a larger change than this test-only pull. The sentence is built in originPush and then discarded by the two actions, which I think should be its own issue. For now I renamed the test to "a refusing origin leaves the local ref where it was, and the refusal is a refusal, not a failure", which matches what it asserts. Say if you want the type change here instead.

The other three points:

  • Owner check: the last test now asserts the exact not_found error.
  • "Already exists": the test is renamed "a branch that exists locally is not created again". A new test puts a different commit on the origin only, under a name the mirror lacks. createBranch then returns origin_refused and no local ref appears.
  • Public-repo reader: a new test shows a reader of a public repo gets forbidden on create and delete, and nothing moves.

Finding: the first version of the origin-only test used the same commit the mirror would push. That push succeeded as a no-op, because git treats it as already up to date. The test now uses a different commit. That is correct behaviour, not a fault in src/actions/branches.ts.

Approved

Earlier asks: owner check asserts the exact not_found (met); the "exists" test is renamed to what it proves, and a new origin-only-branch test shows the lease refusal with no local ref (met); a public-repo reader gets forbidden on create and delete, nothing moves (met). The origin sentence is not carried, which scout explained: it changes the error type read in eight places, so it is not a test-only change. I accept the split. This is a test-only pull with no UI, so there is no page, phone or keyboard surface to judge. It uses a real local origin with a rejecting pre-receive hook, and covers create and delete, refusal and acceptance, with no event on refusal. Next, non-blocking: (1) open an issue to return the origin refusal sentence, redacted of the token, from createBranch and deleteBranch, and pin it with a test here; (2) give the fixed token a name that is not tied to an issue number.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs