iterate.com / git

git clone https://git.iterate.com/repos/git

A member's git signs in with the iterate CLI, and nothing says whether a repo exists #1

merged git-https-credential-helper was squashed into main as d81ead3 by jonas, 2026-11-26 20:08 UTC. jonas opened it 2026-11-26 13:09 UTC.

Git's three requests read the boundary's stamp, as a page does. A member's git gets a token of the app's own on the way to Artifacts: the kept read token for a fetch, a write token minted for the one request of a push.

A request that is no member's gets one answer whether the repo is there or not: a refused credential 401 with words, the helper's marker and no credential 401 with a Basic challenge, and neither 404 with the setup command. Before, a repo that is not public answered 401 and a missing one 404 with its name.

Who pushed which refs is on the repo's log: `git/pushed { by, refs }`. A caller's own Artifacts token is still passed on (an agent's script, git in a sandbox).

**Needs the kernel's pull deployed first** (host tokens, Basic at the boundary). Until then a member's git has no way to be stamped, and only an Artifacts token works. A merge here is live in seconds: do not merge before the stack runs that kernel.

Card: tasks/implement-git-https-credential-helper-and-prove-it-on-a-dev-mind.md. Design: https://docs.iterate.com/notes/git-https-auth-design-2026-11-26.html (decisions 1 to 5 answered by Misha, 26 Nov 2026 12:34 UTC).

Session: claude 4bfd7dc5-ae25-44a2-9e97-71e8cda6eb3a on beelink

Conversation

Nobody has said anything yet.

Sign in to comment or to merge.

Files

3 files changed

M README.md
@@ -17,6 +17,31 @@
 /repos/<name>/pull/<number>        one pull: its conversation and what it changes
 ```
 
+## Git on your computer
+
+A public repo is cloned with no sign-in. Any other repo, and every push, is for a member of the
+mind. Set git up once on a computer (it needs Node 22 or newer):
+
+```sh
+npx iterate git setup git.<domain>
+```
+
+It signs you in to the mind if this computer is not signed in (in a browser here, or with a link
+and a code for a browser on another device), and sets git's credential helper for this one host.
+After that, plain `git clone`, `git pull` and `git push` work, and nothing asks for a password.
+
+- A git that was never set up gets "there is no repo here that you can read" with that command,
+  for a repo that is not public and for a repo that does not exist alike.
+- When the sign-in has ended (it ends after seven days without use, or when a member ends it on
+  the mind's `/sessions` page), git says so and names the same command. With a person at the
+  terminal, git signs in again by itself and then goes on.
+- Git gets a token that is for this host alone and lasts an hour at most. No Artifacts token
+  leaves the mind: the app adds its own on the way to Artifacts.
+- In a sandbox of the mind the same command signs nobody in: git's helper there asks the mind
+  for a token for the one repo, through the sandbox's own session, and this app passes it on.
+  So does an agent that sends an Artifacts token of its own (`itx.cfArtifacts`).
+- Who pushed which refs is on the repo's log: `git/pushed { by, refs }`.
+
 ## Propose a change
 
 ```sh
M app.ts
@@ -19,19 +19,35 @@
 // (what a pull is), and public/ (what the browser runs).
 //
 // WHO MAY READ. A repo that worker.ts lists as public is for anyone: its pages, its pulls, and a
-// clone with no credential. Any other repo's pages are for a member of the mind, and git needs
-// the caller's own Artifacts token for it. A push needs that token for every repo.
+// clone with no credential. Any other repo's pages, and git on it, are for a member of the mind.
+// A push is a member's, on every repo.
 //
 // WHO MAY WRITE. A member alone opens a pull, comments and merges: the page does each through the
 // member's own `itx` (public/mind.js, over the socket that `host.auth.memberPage` answers), so the
 // platform records who did it. This file writes nothing of a pull.
 //
-// THE REMOTE IS A PASS-THROUGH. Each of git's three requests goes to the repo's Cloudflare
-// Artifacts remote as it came, body streamed, answer streamed back. The app adds three things.
-// The address is the mind's own. For a public repo it adds a read token of its own. And after a
-// push that moved `main` it tells the mind's repo, which is how the mind comes to publish a push
-// to a repo that was made after the deploy. Artifacts checks every token, not this file.
+// WHO GIT IS. The platform says it, as for a page: git sends a token of the mind for this one
+// host, which the `iterate` CLI's credential helper hands it (`npx iterate git setup <host>`),
+// and the boundary checks that token on every request and stamps the member. This file reads the
+// stamp. A sign-in that ended, or a member who was removed, has no stamp at the next request.
 //
+// THE REMOTE. Each of git's three requests goes to the repo's Cloudflare Artifacts remote, body
+// streamed, answer streamed back, WITH A TOKEN OF THE APP'S OWN: a read token that this isolate
+// keeps in memory while it lasts, or a write token that is minted for the one request of a push.
+// A member's git never sees an Artifacts token. After a push the app writes who pushed which refs
+// on the repo's log (`git/pushed`), and after one that moved `main` it tells the mind's repo,
+// which is how the mind comes to publish a push to a repo that was made after the deploy.
+//
+// A CALLER'S OWN ARTIFACTS TOKEN IS PASSED ON, and Artifacts checks it. Only code of the mind
+// can mint one (`itx.cfArtifacts`): an agent's script, and git's helper in a sandbox of the mind,
+// which has no person to sign in and asks the mind for the one repo's token through the
+// sandbox's own session. Nobody is written as the one who pushed then: Artifacts knows a token
+// and no person.
+//
+// WHAT A REQUEST WITH NO SIGN-IN IS TOLD is the same for a repo that is not public and for no
+// repo at all, so the answer says nothing of what exists (`refusal`). Every refusal is on git's
+// first request and is plain text: git shows those words, and shows none for a later request.
+//
 // NOTHING OF THE REMOTE IS WRITTEN DOWN. Where Artifacts serves a repo is asked of Artifacts, and
 // a read token is minted for the request: both are kept in this isolate's memory, a token while it
 // lasts, so the two requests of one clone on one connection share them. Until 26 Nov 2026 both
@@ -41,7 +57,7 @@
 // A token lives ten minutes now. Most connections get a new isolate, so most clones ask twice and
 // mint once: the remote takes about 60 ms and a mint 150 (measured on iterate.com, 26 Nov 2026,
 // and on tthq.app, 24 Nov 2026), and the two run at the same time. NOTHING BOUNDS THE MINTS ACROSS
-// ISOLATES: each anonymous read that reaches a new isolate mints one. What stops a push is
+// ISOLATES: each read that reaches a new isolate mints one. What stops a push is
 // Artifacts' own limit of 64 MiB a push, with the same words through this app as straight to
 // Artifacts.
 import { reportIssue } from "iterate/lib";
@@ -77,25 +93,31 @@
 const GIT_PATH =
   /^(\/repos\/[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*?)\/(info\/refs|git-upload-pack|git-receive-pack)$/;
 
-/** What git sends that Artifacts needs. A cookie or a stamp of the mind's never leaves. */
+/** What git sends that Artifacts needs. A cookie or a stamp of the mind's never leaves, and the
+ *  credential that goes is set by `remote`. */
 const REQUEST_HEADERS = [
   "accept",
   "accept-encoding",
-  "authorization",
   "content-encoding",
   "content-type",
   "git-protocol",
   "user-agent",
 ];
-const ANSWER_HEADERS = ["cache-control", "content-type", "expires", "pragma", "www-authenticate"];
+/** Never Artifacts' own challenge: it would have git ask a person for a password. */
+const ANSWER_HEADERS = ["cache-control", "content-type", "expires", "pragma"];
 
-/** How long a read token of the app's lives. One serves the anonymous reads that reach this
- *  isolate in that time, and no other isolate has it. */
+/** How long a read token of the app's lives. One serves the reads that reach this isolate in
+ *  that time, a member's and for a public repo anyone's, and no other isolate has it. */
 const READ_TOKEN_SECONDS = 600;
+/** A write token is for the one request it was minted for, and is kept nowhere. */
+const WRITE_TOKEN_SECONDS = 300;
 
+/** The header that `iterate git setup` has git send (iterate/cli git.ts `GIT_MARKER_HEADER`): this
+ *  git has the credential helper. It is public and proves nothing. */
+const HELPER_MARKER = "x-iterate-git";
+
 /** What one isolate knows of the repos' remotes, in memory alone and gone with the isolate: where
- *  Artifacts serves each repo, and for a public repo a read token as git sends one, with the
- *  moment it ends. Each is kept as it is being asked for, so two requests that come together ask
+ *  Artifacts serves each repo, and a read token of it as git sends one, with the moment it ends. Each is kept as it is being asked for, so two requests that come together ask
  *  once. */
 type Remotes = {
   addresses: Map<string, Promise<string>>;
@@ -183,15 +205,22 @@
   const service = verb === "info/refs" ? url.searchParams.get("service") : verb;
   if (service !== "git-upload-pack" && service !== "git-receive-pack")
     return new Response("git: only smart HTTP is served here\n", { status: 403 });
+  const write = service === "git-receive-pack";
 
+  // a member, as the boundary stamped them; another mind's stamp is no member's
+  const stamped = host.auth.principal(request);
+  const member = stamped && stamped.kind !== "mind" ? stamped : null;
+  // what the boundary did not take as a token of its own is still here
+  const presented = request.headers.get("authorization");
+  const ownToken = !member && presented && isArtifactsToken(presented) ? presented : null;
+  const anonymousRead = !write && publicRepos.includes(repo);
+  if (!member && !ownToken && !anonymousRead) return refusal(request, url, presented);
+
   const headers = new Headers();
   for (const name of REQUEST_HEADERS) {
     const value = request.headers.get(name);
     if (value) headers.set(name, value);
   }
-  const anonymousRead =
-    !headers.has("authorization") && service === "git-upload-pack" && publicRepos.includes(repo);
-
   const now = Date.now();
   let address: string;
   let authorization: string | undefined;
@@ -207,10 +236,11 @@
       asked = itx.cfArtifacts.get(repo).then((artifacts) => artifacts.remote());
       once(remotes.addresses, asked, asked);
     }
-    // a request with its own token needs the address alone; an anonymous read needs a token too.
-    // One that ends within a minute could end in the middle of this clone.
-    let token = anonymousRead ? remotes.readTokens.get(repo) : undefined;
-    if (anonymousRead && !(token && token.until > now + 60_000)) {
+    // A read with no token of its own, a member's or anyone's of a public repo, gets the app's
+    // read token. One that ends within a minute could end in the middle of this clone.
+    const reads = !write && !ownToken;
+    let token = reads ? remotes.readTokens.get(repo) : undefined;
+    if (reads && !(token && token.until > now + 60_000)) {
       const minted = itx.cfArtifacts
         .get(repo)
         .then((artifacts) => artifacts.createToken("read", READ_TOKEN_SECONDS))
@@ -218,8 +248,21 @@
       token = { authorization: minted, until: now + READ_TOKEN_SECONDS * 1000 };
       once(remotes.readTokens, token, minted);
     }
-    [address, authorization] = await Promise.all([asked, token?.authorization]);
+    // a member's push: a write token for this one request, kept nowhere
+    const forPush =
+      write && !ownToken
+        ? itx.cfArtifacts
+            .get(repo)
+            .then((artifacts) => artifacts.createToken("write", WRITE_TOKEN_SECONDS))
+            .then((made) => `Basic ${btoa(`x:${made.plaintext}`)}`)
+        : undefined;
+    [address, authorization] = await Promise.all([
+      asked,
+      ownToken ?? forPush ?? token?.authorization,
+    ]);
   } catch (error) {
+    // only a member is told that a repo is not there, or was not read
+    if (!member) return refusal(request, url, presented);
     const message = error instanceof Error ? error.message : String(error);
     return new Response(`git: no repo at ${repo} (${message})\n`, {
       status: /not found|10200/i.test(message) ? 404 : 502,
@@ -233,20 +276,78 @@
     body: request.body,
     redirect: "manual",
   });
+  // Artifacts refused the caller's own token: the app's answer, which names no repo
+  if (ownToken && [401, 403, 404].includes(upstream.status)) return refusal(request, url, presented);
   const answerHeaders = new Headers();
   for (const name of ANSWER_HEADERS) {
     const value = upstream.headers.get(name);
     if (value) answerHeaders.set(name, value);
   }
-  // A PUSH THAT MOVED MAIN: the repo is told, so the mind publishes what was pushed. Git's report
-  // of a push is small, so it is read whole and passed on as it came.
+  // A PUSH: git's report is small, so it is read whole and passed on as it came. Who pushed is
+  // written on the repo's log, and a push that moved main is told to the repo, so the mind
+  // publishes what was pushed.
   if (verb === "git-receive-pack" && upstream.ok) {
     const report = await upstream.arrayBuffer();
-    if (new TextDecoder().decode(report).includes("ok refs/heads/main\n"))
-      await tellOfNewTip(host, repo);
+    const refs = [...new TextDecoder().decode(report).matchAll(/ok (refs\/\S+)\n/g)].map(
+      (line) => line[1]!,
+    );
+    if (member && refs.length > 0) await recordPush(host, repo, member.email || member.actor, refs);
+    if (refs.includes("refs/heads/main")) await tellOfNewTip(host, repo);
     return new Response(report, { status: upstream.status, headers: answerHeaders });
   }
   return new Response(upstream.body, { status: upstream.status, headers: answerHeaders });
+}
+
+/** Whether a credential is a Cloudflare Artifacts token (`art_…`), as a bearer or as the password
+ *  of Basic: the one credential of a caller's own that the app passes on. */
+function isArtifactsToken(authorization: string): boolean {
+  const [scheme, value = ""] = authorization.split(/ +/, 2);
+  if (scheme?.toLowerCase() === "bearer") return value.startsWith("art_");
+  if (scheme?.toLowerCase() !== "basic") return false;
+  try {
+    const pair = atob(value);
+    return pair.slice(pair.indexOf(":") + 1).startsWith("art_");
+  } catch {
+    return false;
+  }
+}
+
+/** WHAT A REQUEST THAT IS NO MEMBER'S IS TOLD, the same whether the repo is there or not:
+ *
+ *    a credential came, and nobody took it    401, "this sign-in has ended": git forgets the token
+ *    no credential, the helper's marker       401 with a challenge: git asks the helper
+ *    no credential, no marker                 404, with the command that sets the helper up
+ *
+ *  Git shows a 404's words and a refused credential's, and never a first 401's: so a git with no
+ *  helper gets the 404, which is the only way to put its next step on the screen. The challenge
+ *  is `Basic`, never the platform's `Bearer realm="iterate"`, which the boundary would turn into
+ *  a sign-in page. */
+function refusal(request: Request, url: URL, presented: string | null): Response {
+  const setup = `  npx iterate git setup ${url.hostname}\n`;
+  const plain = { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" };
+  const challenge = { ...plain, "www-authenticate": 'Basic realm="iterate git"' };
+  if (presented)
+    return new Response(
+      `iterate: this sign-in has ended or was taken away.\nSign in again, then run the same command:\n${setup}`,
+      { status: 401, headers: challenge },
+    );
+  if (request.headers.has(HELPER_MARKER))
+    return new Response("iterate: sign in to read this repo\n", { status: 401, headers: challenge });
+  return new Response(
+    `iterate: there is no repo here that you can read.\nIf it is private, sign in once, then run the same command again:\n${setup}`,
+    { status: 404, headers: plain },
+  );
+}
+
+/** Writes who pushed which refs on the repo's log. Artifacts knows a token and no person, so
+ *  nothing else says it. A failure is reported and the push stands. */
+async function recordPush(host: Host, repo: string, by: string, refs: string[]): Promise<void> {
+  try {
+    using itx = host.getItx();
+    await itx.cd(repo).append({ type: "git/pushed", payload: { by, refs } });
+  } catch (error) {
+    reportIssue("git-app.push-not-recorded", error, { repo });
+  }
 }
 
 /** Tells a repo of the mind that its main has a new tip. Cloudflare tells the mind of a push too,
M tests/app.test.mjs
@@ -60,6 +60,8 @@
   });
   mind.kv["git-app:/repos/kernel"] = entry;
   const git = gitApp({ public: ["/repos/kernel"], ...look });
+  // a token of the caller's own, which the app passes on
+  const own = `Basic ${btoa("x:art_v2_the-callers-own")}`;
 
   await git.fetch(
     new Request("https://git.example.com/repos/kernel/info/refs?service=git-upload-pack"),
@@ -67,13 +69,13 @@
   );
   await git.fetch(
     new Request("https://git.example.com/repos/kernel/info/refs?service=git-upload-pack", {
-      headers: { authorization: "Basic a-callers-own" },
+      headers: { authorization: own },
     }),
     mind,
   );
   assert.deepEqual(
     remote.requests.map(({ authorization }) => authorization),
-    [`Basic ${btoa("x:read-token-1-of-/repos/kernel")}`, "Basic a-callers-own"],
+    [`Basic ${btoa("x:read-token-1-of-/repos/kernel")}`, own],
   );
   // no credential went to the address in the kv, and the app wrote nothing there
   assert.deepEqual(elsewhere.requests, []);
@@ -108,32 +110,24 @@
   assert.equal((await read(gitApp({ public: ["/repos/kernel"], ...look }))).status, 200);
   // the config's next publish: the list no longer names the repo
   const refused = await read(gitApp({ public: [], ...look }));
-  assert.equal(refused.status, 401);
-  assert.equal(remote.requests.at(-1).authorization, undefined);
+  // the answer that says nothing of what exists, and Artifacts is not asked
+  assert.equal(refused.status, 404);
+  assert.equal(remote.requests.length, 1);
   assert.equal(mind.minted.length, 1);
 });
 
-test("a repo that is not listed as public is read with the caller's own token, and with none it gets the remote's 401", async () => {
+test("a member's git reads a repo that is not public with a read token of the app's own, and the member's credential never leaves", async () => {
   await using remote = await artifactsRemote();
   const mind = fakeMind(remote);
   const git = gitApp({ public: ["/repos/kernel"], ...look });
 
-  const refused = await git.fetch(
-    new Request("https://git.example.com/repos/config/info/refs?service=git-upload-pack"),
-    mind,
-  );
-  assert.equal(refused.status, 401);
-  // git asks for a password when it reads this header
-  assert.equal(refused.headers.get("www-authenticate"), 'Basic realm="artifacts"');
-
-  const own = `Basic ${btoa("misha:the-callers-own-token")}`;
-  const allowed = await git.fetch(
+  const refs = await git.fetch(
     new Request("https://git.example.com/repos/config.git/info/refs?service=git-upload-pack", {
-      headers: { authorization: own, cookie: "session=of-the-mind", "git-protocol": "version=2" },
+      headers: { ...asMember, cookie: "session=of-the-mind", "git-protocol": "version=2" },
     }),
     mind,
   );
-  assert.equal(allowed.status, 200);
+  assert.equal(refs.status, 200);
   assert.deepEqual(
     remote.requests.map(({ url, authorization, cookie, gitProtocol }) => ({
       url,
@@ -144,53 +138,171 @@
     [
       {
         url: "/remote/config/info/refs?service=git-upload-pack",
-        authorization: undefined,
-        cookie: undefined,
-        gitProtocol: undefined,
-      },
-      {
-        url: "/remote/config/info/refs?service=git-upload-pack",
-        authorization: own,
+        authorization: `Basic ${btoa("x:read-token-1-of-/repos/config")}`,
         // a cookie of the mind's never leaves; what git says of its protocol does
         cookie: undefined,
         gitProtocol: "version=2",
       },
     ],
   );
-  assert.deepEqual(mind.minted, []);
+  assert.deepEqual(mind.minted, [{ repo: "/repos/config", scope: "read", ttlSeconds: 600 }]);
+  // in this isolate's memory alone
+  assert.deepEqual(mind.kv, {});
 });
 
-test("a push needs the caller's own token, to a public repo too: the app adds none", async () => {
+test("a member's push goes with a write token minted for that one request, and the repo's log says who pushed what", async () => {
   await using remote = await artifactsRemote();
   const mind = fakeMind(remote);
   const git = gitApp({ public: ["/repos/kernel"], ...look });
 
-  const refused = await git.fetch(
-    new Request("https://git.example.com/repos/kernel/info/refs?service=git-receive-pack"),
+  const refs = await git.fetch(
+    new Request("https://git.example.com/repos/kernel/info/refs?service=git-receive-pack", {
+      headers: asMember,
+    }),
     mind,
   );
-  assert.equal(refused.status, 401);
-
-  const own = `Basic ${btoa("x:a-write-token")}`;
+  assert.equal(refs.status, 200);
   const pushed = await git.fetch(
     new Request("https://git.example.com/repos/kernel/git-receive-pack", {
       method: "POST",
-      headers: { authorization: own },
-      body: "the pack",
+      headers: asMember,
+      body: "the pack, for refs/heads/add-b",
     }),
     mind,
   );
-  assert.equal(await pushed.text(), "unpack ok\n");
+  assert.equal(await pushed.text(), "unpack ok\nok refs/heads/add-b\n");
   assert.deepEqual(
     remote.requests.map(({ url, authorization }) => ({ url, authorization })),
     [
-      { url: "/remote/kernel/info/refs?service=git-receive-pack", authorization: undefined },
-      { url: "/remote/kernel/git-receive-pack", authorization: own },
+      {
+        url: "/remote/kernel/info/refs?service=git-receive-pack",
+        authorization: `Basic ${btoa("x:write-token-1-of-/repos/kernel")}`,
+      },
+      {
+        url: "/remote/kernel/git-receive-pack",
+        authorization: `Basic ${btoa("x:write-token-2-of-/repos/kernel")}`,
+      },
     ],
   );
+  assert.deepEqual(mind.minted, [
+    { repo: "/repos/kernel", scope: "write", ttlSeconds: 300 },
+    { repo: "/repos/kernel", scope: "write", ttlSeconds: 300 },
+  ]);
+  // no write token is kept
+  assert.doesNotMatch(JSON.stringify(mind.kv), /write-token/);
+  assert.deepEqual(mind.appended, [
+    {
+      path: "/repos/kernel",
+      event: { type: "git/pushed", payload: { by: "ada@example.com", refs: ["refs/heads/add-b"] } },
+    },
+  ]);
+});
+
+test("with no sign-in, a repo that is not public and a repo that is not there get the same answer, and so does a push", async () => {
+  await using remote = await artifactsRemote();
+  const mind = fakeMind(remote);
+  const git = gitApp({ public: ["/repos/kernel"], ...look });
+  const asked = async (path, headers = {}) => {
+    const answer = await git.fetch(new Request(`https://git.example.com${path}`, { headers }), mind);
+    return {
+      status: answer.status,
+      challenge: answer.headers.get("www-authenticate"),
+      type: answer.headers.get("content-type"),
+      text: await answer.text(),
+    };
+  };
+  const read = "/info/refs?service=git-upload-pack";
+
+  // A GIT WITH NO HELPER: a 404, whose words git shows, with the command to run
+  const fresh = await asked(`/repos/config${read}`);
+  assert.deepEqual(fresh, {
+    status: 404,
+    challenge: null,
+    type: "text/plain; charset=utf-8",
+    text: "iterate: there is no repo here that you can read.\nIf it is private, sign in once, then run the same command again:\n  npx iterate git setup git.example.com\n",
+  });
+  assert.deepEqual(await asked(`/repos/missing${read}`), fresh);
+  assert.deepEqual(await asked("/repos/kernel/info/refs?service=git-receive-pack"), fresh);
+
+  // A GIT WITH THE HELPER and no credential yet: a 401, so git asks the helper
+  const marked = { "x-iterate-git": "1" };
+  const challenged = await asked(`/repos/config${read}`, marked);
+  assert.deepEqual(
+    { status: challenged.status, challenge: challenged.challenge },
+    { status: 401, challenge: 'Basic realm="iterate git"' },
+  );
+  assert.deepEqual(await asked(`/repos/missing${read}`, marked), challenged);
+
+  // A CREDENTIAL THAT THE BOUNDARY DID NOT TAKE (a sign-in that ended): a 401 with words, and git
+  // forgets the token
+  const ended = { ...marked, authorization: `Basic ${btoa("iterate:a-token-that-ended")}` };
+  const refused = await asked(`/repos/config${read}`, ended);
+  assert.deepEqual(refused, {
+    status: 401,
+    challenge: 'Basic realm="iterate git"',
+    type: "text/plain; charset=utf-8",
+    text: "iterate: this sign-in has ended or was taken away.\nSign in again, then run the same command:\n  npx iterate git setup git.example.com\n",
+  });
+  assert.deepEqual(await asked(`/repos/missing${read}`, ended), refused);
+
+  // nothing was asked of Artifacts, and nothing was minted or kept
+  assert.deepEqual(remote.requests, []);
   assert.deepEqual(mind.minted, []);
+  assert.deepEqual(mind.kv, {});
 });
 
+test("a public repo is still read by a git whose sign-in ended", async () => {
+  await using remote = await artifactsRemote();
+  const mind = fakeMind(remote);
+  const git = gitApp({ public: ["/repos/kernel"], ...look });
+
+  const refs = await git.fetch(
+    new Request("https://git.example.com/repos/kernel/info/refs?service=git-upload-pack", {
+      headers: { authorization: `Basic ${btoa("iterate:a-token-that-ended")}` },
+    }),
+    mind,
+  );
+  assert.equal(refs.status, 200);
+  assert.equal(remote.requests[0].authorization, `Basic ${btoa("x:read-token-1-of-/repos/kernel")}`);
+});
+
+test("a caller's own Artifacts token is passed on as it came, and one that Artifacts refuses gets the answer that names no repo", async () => {
+  await using remote = await artifactsRemote();
+  const mind = fakeMind(remote);
+  const git = gitApp({ public: [], ...look });
+  const own = "Bearer art_v2_the-callers-own";
+
+  const pushed = await git.fetch(
+    new Request("https://git.example.com/repos/kernel/git-receive-pack", {
+      method: "POST",
+      headers: { authorization: own },
+      body: "the pack, for refs/heads/main",
+    }),
+    mind,
+  );
+  assert.equal(await pushed.text(), "unpack ok\nok refs/heads/main\n");
+  assert.equal(remote.requests[0].authorization, own);
+  assert.deepEqual(mind.minted, []);
+  // Artifacts knows a token and no person: nobody is written as the one who pushed
+  assert.deepEqual(mind.appended, []);
+  assert.deepEqual(mind.announced, ["/repos/kernel"]);
+
+  const read = "/info/refs?service=git-upload-pack";
+  const refusedBy = async (path) => {
+    const answer = await git.fetch(
+      new Request(`https://git.example.com${path}`, {
+        headers: { authorization: `Basic ${btoa("x:art_v2_refused")}` },
+      }),
+      mind,
+    );
+    return [answer.status, await answer.text()];
+  };
+  const refused = await refusedBy(`/repos/config${read}`);
+  assert.equal(refused[0], 401);
+  assert.match(refused[1], /^iterate: this sign-in has ended/);
+  assert.deepEqual(await refusedBy(`/repos/missing${read}`), refused);
+});
+
 test("a push that moved main tells the mind's repo, so the mind publishes what was pushed; a push of another branch tells it nothing", async () => {
   await using remote = await artifactsRemote();
   const mind = fakeMind(remote);
@@ -199,7 +311,7 @@
     git.fetch(
       new Request("https://git.example.com/repos/kernel/git-receive-pack", {
         method: "POST",
-        headers: { authorization: `Basic ${btoa("x:a-write-token")}` },
+        headers: asMember,
         body: `the pack, for ${ref}`,
       }),
       mind,
@@ -215,7 +327,7 @@
   assert.deepEqual(mind.announced, ["/repos/kernel"]);
 });
 
-test("a push stands when the mind's repo could not be told: git gets the remote's report", async () => {
+test("a push stands when the mind's repo could not be told, or its log not written: git gets the remote's report", async () => {
   await using remote = await artifactsRemote();
   const mind = fakeMind(remote);
   mind.away.add("/repos/kernel");
@@ -224,7 +336,7 @@
   const pushed = await git.fetch(
     new Request("https://git.example.com/repos/kernel/git-receive-pack", {
       method: "POST",
-      headers: { authorization: `Basic ${btoa("x:a-write-token")}` },
+      headers: asMember,
       body: "the pack, for refs/heads/main",
     }),
     mind,
@@ -233,6 +345,7 @@
   assert.equal(pushed.status, 200);
   assert.equal(await pushed.text(), "unpack ok\nok refs/heads/main\n");
   assert.deepEqual(mind.announced, []);
+  assert.deepEqual(mind.appended, []);
 });
 
 test("a read token that is about to end is replaced, and the repo's remote is not asked for again", async () => {
@@ -280,13 +393,15 @@
   assert.deepEqual(mind.kv, {});
 });
 
-test("a repo the mind does not have is not found", async () => {
+test("a member is told when the mind has no such repo", async () => {
   await using remote = await artifactsRemote();
   const mind = fakeMind(remote);
   const git = gitApp({ public: ["/repos/kernel"], ...look });
 
   const answer = await git.fetch(
-    new Request("https://git.example.com/repos/missing/info/refs?service=git-upload-pack"),
+    new Request("https://git.example.com/repos/missing/info/refs?service=git-upload-pack", {
+      headers: asMember,
+    }),
     mind,
   );
   assert.equal(answer.status, 404);
@@ -299,14 +414,20 @@
 /** What worker.ts hands the app for its pages, which no test here reads. */
 const look = { icon: () => new Response("the icon") };
 
+/** A request that the boundary stamped as a member's: the fake mind reads this header in the
+ *  stamp's place (`fakeMind`). */
+const asMember = { "x-test-member": "ada@example.com" };
+
 /** The mind as the app reaches it: a kv, and the Artifacts repos `kernel` and `config`, served
  *  by `remote`. It records each token it mints, each repo whose remote it was asked for, and each
- *  repo that was told its main has a new tip. A repo in `away` throws when it is told. */
+ *  repo that was told its main has a new tip, and each event appended to a repo's log. A repo in
+ *  `away` throws when it is told or written to. */
 function fakeMind(remote) {
   const kv = {};
   const minted = [];
   const remotesAsked = [];
   const announced = [];
+  const appended = [];
   const away = new Set();
   const repos = ["/repos/kernel", "/repos/config"];
   const itx = {
@@ -339,6 +460,12 @@
         },
       }),
     },
+    cd: (path) => ({
+      append: async (event) => {
+        if (away.has(path)) throw new Error(`the repo ${path} is away`);
+        appended.push({ path, event });
+      },
+    }),
     [Symbol.dispose]() {},
   };
   // what is no git request is asked whether it is a member's socket: here none is
@@ -347,15 +474,23 @@
     minted,
     remotesAsked,
     announced,
+    appended,
     away,
     getItx: () => itx,
-    auth: { memberPage: () => null },
+    auth: {
+      memberPage: () => null,
+      // the boundary's stamp, which the tests write as a header of their own
+      principal: (request) => {
+        const email = request.headers.get("x-test-member");
+        return email ? { actor: "user_ada", email } : null;
+      },
+    },
   };
 }
 
 /** A repo's Artifacts remote: a server on this machine that records each request and answers as
- *  git's smart HTTP does in outline. A request with no credential gets Artifacts' own 401, but
- *  for a read with a read token or any request with a caller's token. */
+ *  git's smart HTTP does in outline. A request with no credential, or with the one token that
+ *  the tests call refused, gets Artifacts' own 401. */
 async function artifactsRemote() {
   // Node's fetch wants `duplex: "half"` said for a body that is a stream, which the app's is.
   // workerd, where the app runs, takes a stream as it is.
@@ -374,7 +509,9 @@
       cookie: request.headers.cookie,
       gitProtocol: request.headers["git-protocol"],
     });
-    if (!request.headers.authorization) {
+    const credential = request.headers.authorization || "";
+    const refused = credential.includes("refused") || credential === `Basic ${btoa("x:art_v2_refused")}`;
+    if (!credential || refused) {
       response.writeHead(401, { "www-authenticate": 'Basic realm="artifacts"' }).end();
       return;
     }