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.
| The plan says what g1t is for without measuring it against other products | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { capShare, formatCap, lines, settingsFromForm, tri, workflowDomainLine, workflowDomains } from "./guardrails.ts"; | |
| 5 | ||
| 6 | const catalog = { | |
| 7 | registries: ["npm", "pypi", "crates"], | |
| 8 | kinds: ["implement", "review"] as const, | |
| 9 | }; | |
| 10 | ||
| 11 | function form(entries: Record<string, string>): FormData { | |
| 12 | const data = new FormData(); | |
| 13 | for (const [key, value] of Object.entries(entries)) data.set(key, value); | |
| 14 | return data; | |
| 15 | } | |
| 16 | ||
| 17 | test("workflow-only domains are read one per line, and written back the same way", () => { | |
| 18 | const read = workflowDomains( | |
| 19 | " api.cloudflare.com | deploy.yml | production \n\n*.example.com\nhooks.example.com | | staging, production\nci.example.com | ci.yml, release.yml\n | deploy.yml", | |
| 20 | ); | |
| 21 | assert.deepEqual(read, [ | |
| 22 | { domain: "api.cloudflare.com", workflows: ["deploy.yml"], environments: ["production"] }, | |
| 23 | { domain: "*.example.com", workflows: [], environments: [] }, | |
| 24 | { domain: "hooks.example.com", workflows: [], environments: ["staging", "production"] }, | |
| 25 | { domain: "ci.example.com", workflows: ["ci.yml", "release.yml"], environments: [] }, | |
| 26 | ]); | |
| 27 | assert.deepEqual(read.map(workflowDomainLine), [ | |
| 28 | "api.cloudflare.com | deploy.yml | production", | |
| 29 | "*.example.com", | |
| 30 | "hooks.example.com | | staging, production", | |
| 31 | "ci.example.com | ci.yml, release.yml", | |
| 32 | ]); | |
| 33 | const settings = settingsFromForm(form({ workflowDomains: "api.cloudflare.com | deploy.yml | production" }), catalog); | |
| 34 | assert.deepEqual(settings.workflowDomains, [{ domain: "api.cloudflare.com", workflows: ["deploy.yml"], environments: ["production"] }]); | |
| 35 | }); | |
| 36 | ||
| 37 | test("an untouched form inherits everything", () => { | |
| 38 | const settings = settingsFromForm(form({ restrictNetwork: "inherit", registries: "inherit" }), catalog); | |
| 39 | assert.equal(settings.restrictNetwork, null); | |
| 40 | assert.equal(settings.registries, null); | |
| 41 | assert.deepEqual(settings.minutes, {}); | |
| 42 | assert.deepEqual(settings.domains, []); | |
| 43 | }); | |
| 44 | ||
| 45 | test("choices of a level's own are kept", () => { | |
| 46 | const settings = settingsFromForm( | |
| 47 | form({ | |
| 48 | restrictNetwork: "off", | |
| 49 | registries: "custom", | |
| 50 | "registry:npm": "on", | |
| 51 | "registry:crates": "on", | |
| 52 | "minutes:implement": "45", | |
| 53 | "minutes:review": "", | |
| 54 | domains: "api.stripe.com\n\n api.stripe.com \r\n*.example.com", | |
| 55 | }), | |
| 56 | catalog, | |
| 57 | ); | |
| 58 | assert.equal(settings.restrictNetwork, false); | |
| 59 | assert.deepEqual(settings.registries, ["npm", "crates"]); | |
| 60 | assert.deepEqual(settings.minutes, { implement: 45 }); | |
| 61 | assert.deepEqual(settings.domains, ["api.stripe.com", "*.example.com"]); | |
| 62 | }); | |
| 63 | ||
| 64 | test("nonsense is passed on for the service to refuse", () => { | |
| 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 | const settings = settingsFromForm(form({ "minutes:implement": "soon" }), catalog); |
| The plan says what g1t is for without measuring it against other products | 66 | assert.equal(settings.minutes?.implement, 0); |
| 67 | }); | |
| 68 | ||
| 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. | 69 | test("a cap reads as dollars, or no cap", () => { |
| The plan says what g1t is for without measuring it against other products | 70 | assert.equal(formatCap(null), "no cap"); |
| 71 | assert.equal(formatCap(5), "$5.00"); | |
| 72 | }); | |
| 73 | ||
| 74 | test("helpers", () => { | |
| 75 | assert.equal(tri(undefined), "inherit"); | |
| 76 | assert.equal(tri(false), "off"); | |
| 77 | assert.deepEqual(lines(" a \nb\na"), ["a", "b"]); | |
| 78 | assert.equal(capShare(1, 4), 0.25); | |
| 79 | assert.equal(capShare(9, 4), 1); | |
| 80 | assert.equal(capShare(1, null), null); | |
| 81 | }); |
This file's history is long; its oldest lines are credited to the oldest commit read.