Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Docs: the inbox, what lands in it and why, its tabs and actions | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { DANGEROUS_SCOPES, OAUTH_DEFAULT_SCOPES, SCOPES, SCOPE_GROUPS } from "@g1t/contracts/scopes"; | |
| 5 | ||
| 6 | import { | |
| 7 | accessSummary, | |
| 8 | consentedScopes, | |
| 9 | describeExpiry, | |
| 10 | everyScope, | |
| 11 | grantFromForm, | |
| 12 | impliedBy, | |
| 13 | matchingPreset, | |
| 14 | normalizeScopes, | |
| 15 | requestedScopes, | |
| 16 | scopesFromForm, | |
| 17 | } from "./token-scopes.ts"; | |
| 18 | ||
| 19 | function form(fields: Record<string, string | string[]>) { | |
| 20 | return { | |
| 21 | get: (name: string) => { | |
| 22 | const value = fields[name]; | |
| 23 | return Array.isArray(value) ? (value[0] ?? null) : (value ?? null); | |
| 24 | }, | |
| 25 | getAll: (name: string) => { | |
| 26 | const value = fields[name]; | |
| 27 | return value === undefined ? [] : Array.isArray(value) ? value : [value]; | |
| 28 | }, | |
| 29 | }; | |
| 30 | } | |
| 31 | ||
| 32 | test("every scope is on the checklist exactly once, admin ones under Dangerous", () => { | |
| 33 | const listed = [...SCOPE_GROUPS.flatMap((group) => group.scopes), ...DANGEROUS_SCOPES]; | |
| 34 | assert.deepEqual([...listed].sort(), SCOPES.map((row) => row.scope).sort()); | |
| 35 | assert.equal(new Set(listed).size, listed.length); | |
| 36 | assert.ok(DANGEROUS_SCOPES.every((scope) => scope.endsWith(":admin") || scope.endsWith(":delete"))); | |
| 37 | }); | |
| 38 | ||
| 39 | test("ticked boxes store the highest level of each resource", () => { | |
| 40 | const parsed = scopesFromForm( | |
| Merge branch 'worktree-agent-a4babc5b5815f6f3a' | 41 | form({ scope: ["issues:read", "issues:write", "code:read", "agents:run", "memory:write", "bogus:read"] }), |
| Docs: the inbox, what lands in it and why, its tabs and actions | 42 | ); |
| The contracts no longer describe g1t's own agents, and workspaces can keep their AI providers. Every consumer had already stopped using them, so the TypeScript and Rust contracts drop the workspace-agent, ability, look, skill-library, context, runner-agent and mention modules, the chat and docs RPCs agents posted and read through, the folio agent methods, the agent_waiting notification, agent.asked and memory.changed events, AI credit, token and gateway billing types, model routes and sessions, team agents, agent tokens, plan, review, message and confidence types, command rules, cost caps and confidence rules. The agents:run and models:* scopes are no longer offered by any preset, OAuth default or permission form, but a stored token or grant that names them still reads; and the removed operations are gone from the scope table, so the API's check that every operation has exactly one scope is strict again. What stored data needs in order to parse (old run and credential kinds, an agent team lead, retired rules and webhook events, old guardrail and integration settings) still parses, and a run's token is still PrincipalKind::Agent, which now means a run's token and the @g1t rows written before. The customize, marketplace, skills and claude-plugin contracts stay only until the mobile app drops its Customize screens. | 43 | assert.deepEqual(parsed, { ok: true, value: ["code:read", "issues:write"] }); |
| Docs: the inbox, what lands in it and why, its tabs and actions | 44 | assert.deepEqual(normalizeScopes(["repo:read", "repo:admin", "repo:write"]), ["repo:admin"]); |
| 45 | }); | |
| 46 | ||
| 47 | test("full access is null, and nothing ticked is refused", () => { | |
| 48 | assert.deepEqual(scopesFromForm(form({ preset: "full", scope: "issues:read" })), { ok: true, value: null }); | |
| 49 | assert.equal(scopesFromForm(form({ preset: "full" }), { allowFull: false }).ok, false); | |
| 50 | assert.equal(scopesFromForm(form({ preset: "custom" })).ok, false); | |
| Merge branch 'worktree-agent-a4babc5b5815f6f3a' | 51 | assert.deepEqual(grantFromForm(form({ scope: "observability:read" })), { ok: true, value: { scopes: ["observability:read"] } }); |
| Docs: the inbox, what lands in it and why, its tabs and actions | 52 | }); |
| 53 | ||
| 54 | test("a higher level ticks the lower ones of its resource only", () => { | |
| 55 | assert.equal(impliedBy(["issues:write"], "issues:read"), "issues:write"); | |
| 56 | assert.equal(impliedBy(["repo:admin"], "repo:write"), "repo:admin"); | |
| 57 | assert.equal(impliedBy(["issues:write"], "issues:write"), null); | |
| 58 | assert.equal(impliedBy(["issues:write"], "pull_requests:read"), null); | |
| 59 | assert.equal(impliedBy(["code:read"], "code:write"), null); | |
| 60 | }); | |
| 61 | ||
| 62 | test("full access ticks the top level of everything", () => { | |
| 63 | const all = everyScope(); | |
| 64 | assert.ok(all.includes("repo:admin")); | |
| The contracts no longer describe g1t's own agents, and workspaces can keep their AI providers. Every consumer had already stopped using them, so the TypeScript and Rust contracts drop the workspace-agent, ability, look, skill-library, context, runner-agent and mention modules, the chat and docs RPCs agents posted and read through, the folio agent methods, the agent_waiting notification, agent.asked and memory.changed events, AI credit, token and gateway billing types, model routes and sessions, team agents, agent tokens, plan, review, message and confidence types, command rules, cost caps and confidence rules. The agents:run and models:* scopes are no longer offered by any preset, OAuth default or permission form, but a stored token or grant that names them still reads; and the removed operations are gone from the scope table, so the API's check that every operation has exactly one scope is strict again. What stored data needs in order to parse (old run and credential kinds, an agent team lead, retired rules and webhook events, old guardrail and integration settings) still parses, and a run's token is still PrincipalKind::Agent, which now means a run's token and the @g1t rows written before. The customize, marketplace, skills and claude-plugin contracts stay only until the mobile app drops its Customize screens. | 65 | assert.ok(!all.includes("agents:run"), "retired"); |
| Merge branch 'worktree-agent-a4babc5b5815f6f3a' | 66 | assert.ok(!all.some((scope) => scope.startsWith("memory:")), "retired"); |
| Docs: the inbox, what lands in it and why, its tabs and actions | 67 | assert.ok(all.includes("code:write")); |
| 68 | assert.ok(!all.includes("code:read")); | |
| 69 | }); | |
| 70 | ||
| 71 | test("presets are recognised however their scopes are written", () => { | |
| 72 | assert.equal(matchingPreset(null), "full"); | |
| Merge checks: statuses and check runs on every commit | 73 | assert.equal(matchingPreset(["repo:read", "code:write", "packages:write", "workflows:write", "checks:write", "deployments:write"]), "ci"); |
| Docs: the inbox, what lands in it and why, its tabs and actions | 74 | assert.equal(matchingPreset([...OAUTH_DEFAULT_SCOPES]), "agent"); |
| 75 | assert.equal(matchingPreset(["issues:read"]), null); | |
| 76 | }); | |
| 77 | ||
| 78 | test("a token's access reads plainly", () => { | |
| 79 | assert.equal(accessSummary({ scopes: null, legacy: true }), "Legacy · full access"); | |
| 80 | assert.equal(accessSummary({ scopes: null, legacy: false }), "Full access"); | |
| Merge checks: statuses and check runs on every commit | 81 | assert.equal(accessSummary({ scopes: ["code:read", "code:write", "packages:write", "workflows:write", "checks:write", "deployments:write", "repo:read"], legacy: false }), "CI"); |
| Merge branch 'worktree-agent-a4babc5b5815f6f3a' | 82 | assert.equal(accessSummary({ scopes: ["issues:read", "issues:write", "pull_requests:read"], legacy: false }), "2 scopes"); |
| Docs: the inbox, what lands in it and why, its tabs and actions | 83 | assert.equal(accessSummary({ scopes: [], legacy: false }), "No scopes"); |
| 84 | }); | |
| 85 | ||
| 86 | test("an application asking for nothing usable gets the default set, never admin", () => { | |
| 87 | assert.deepEqual(requestedScopes(null), OAUTH_DEFAULT_SCOPES); | |
| 88 | assert.deepEqual(requestedScopes("openid profile *"), OAUTH_DEFAULT_SCOPES); | |
| 89 | assert.ok(!requestedScopes("").some((scope) => scope.endsWith(":admin"))); | |
| 90 | assert.deepEqual(requestedScopes("issues:write nonsense repo:read"), ["repo:read", "issues:write"]); | |
| 91 | }); | |
| 92 | ||
| 93 | test("consent keeps only what was asked for", () => { | |
| 94 | const requested = requestedScopes("repo:read issues:read issues:write"); | |
| 95 | assert.deepEqual(consentedScopes(form({ scope: ["issues:write", "repo:admin", "secrets:admin"] }), requested), ["issues:write"]); | |
| 96 | assert.deepEqual(consentedScopes(form({ scope: ["issues:read", "repo:read"] }), requested), ["repo:read", "issues:read"]); | |
| 97 | assert.deepEqual(consentedScopes(form({}), requested), []); | |
| 98 | }); | |
| 99 | ||
| One kind of access token; presence and status; usernames keep their case; the tour is a miniature of the real app; icons for password managers | 100 | test("expiry words", () => { |
| Docs: the inbox, what lands in it and why, its tabs and actions | 101 | const now = Date.parse("2026-10-05T00:00:00Z"); |
| 102 | assert.equal(describeExpiry(null, now), "No expiry"); | |
| 103 | assert.equal(describeExpiry("2026-10-04T00:00:00Z", now), "Expired"); | |
| 104 | assert.equal(describeExpiry("2026-10-12T00:00:00Z", now), "Expires in 7 days"); | |
| 105 | assert.equal(describeExpiry("2026-10-05T01:00:00Z", now), "Expires in 1 hour"); | |
| 106 | assert.equal(describeExpiry("2027-01-03T00:00:00Z", now), "Expires in 3 months"); | |
| 107 | }); |
This file's history is long; its oldest lines are credited to the oldest commit read.