Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
codeowners-lint.test.ts8.5 KB · 269 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
 * Block J21 — CODEOWNERS validator. Pure lexer + validator + route smokes.
 */

import { describe, it, expect } from "bun:test";
import app from "../app";
import {
  lexCodeowners,
  classifyOwnerToken,
  isPlausiblePattern,
  validateCodeowners,
  __internal,
  type OwnerResolver,
} from "../lib/codeowners-lint";

const allKnownResolver: OwnerResolver = {
  isUser: () => true,
  isTeam: () => true,
};

const noneKnownResolver: OwnerResolver = {
  isUser: () => false,
  isTeam: () => false,
};

function resolver(known: {
  users?: string[];
  teams?: string[];
}): OwnerResolver {
  const u = new Set((known.users || []).map((s) => s.toLowerCase()));
  const t = new Set((known.teams || []).map((s) => s.toLowerCase()));
  return {
    isUser: (x) => u.has(x.toLowerCase()),
    isTeam: (o, team) => t.has(`${o}/${team}`.toLowerCase()),
  };
}

describe("codeowners-lint — lexCodeowners", () => {
  it("ignores blank + comment lines", () => {
    const { rules, totalLines } = lexCodeowners(
      "# comment\n\n# another\n* @alice\n"
    );
    expect(rules).toHaveLength(1);
    expect(rules[0].line).toBe(4);
    expect(rules[0].pattern).toBe("*");
    expect(rules[0].owners).toEqual(["alice"]);
    expect(totalLines).toBeGreaterThan(0);
  });

  it("strips the leading @ from owner tokens", () => {
    const { rules } = lexCodeowners("* @alice @bob\n");
    expect(rules[0].owners).toEqual(["alice", "bob"]);
  });

  it("detects malformed lines with no owners", () => {
    const { malformedLines } = lexCodeowners("*\nfoo/*\n");
    expect(malformedLines.map((m) => m.line)).toEqual([1, 2]);
  });

  it("preserves line numbers with CRLF", () => {
    const { rules } = lexCodeowners("# comment\r\n\r\n* @a\r\n");
    expect(rules[0].line).toBe(3);
  });

  it("drops inline trailing comments", () => {
    const { rules } = lexCodeowners("src/api/** @bob # backend lead");
    expect(rules[0].owners).toEqual(["bob"]);
  });

  it("accepts team-style owner tokens", () => {
    const { rules } = lexCodeowners("docs/ @acme/docs-team");
    expect(rules[0].owners).toEqual(["acme/docs-team"]);
  });
});

describe("codeowners-lint — classifyOwnerToken", () => {
  it("classifies @user tokens as user", () => {
    expect(classifyOwnerToken("alice", true)).toBe("user");
    expect(classifyOwnerToken("a", true)).toBe("user");
    expect(classifyOwnerToken("alice-bob", true)).toBe("user");
  });

  it("classifies @org/team tokens as team", () => {
    expect(classifyOwnerToken("acme/backend", true)).toBe("team");
    expect(classifyOwnerToken("acme/docs-team_2", true)).toBe("team");
  });

  it("classifies plain emails as email", () => {
    expect(classifyOwnerToken("a@b.com", false)).toBe("email");
    expect(classifyOwnerToken("a.b+c@mail.example.io", false)).toBe("email");
  });

  it("rejects bogus tokens", () => {
    expect(classifyOwnerToken("", true)).toBe("invalid");
    expect(classifyOwnerToken("-alice", true)).toBe("invalid"); // leading dash
    expect(classifyOwnerToken("alice/bob/carol", true)).toBe("invalid"); // two slashes
    expect(classifyOwnerToken("alice!", true)).toBe("invalid");
    expect(classifyOwnerToken("plain", false)).toBe("invalid"); // missing @
  });
});

describe("codeowners-lint — isPlausiblePattern", () => {
  it("accepts normal glob patterns", () => {
    expect(isPlausiblePattern("*")).toBe(true);
    expect(isPlausiblePattern("/docs/**")).toBe(true);
    expect(isPlausiblePattern("src/**/*.ts")).toBe(true);
    expect(isPlausiblePattern("[abc].md")).toBe(true);
  });

  it("rejects empty, whitespace, unbalanced brackets", () => {
    expect(isPlausiblePattern("")).toBe(false);
    expect(isPlausiblePattern("foo bar")).toBe(false);
    expect(isPlausiblePattern("[abc")).toBe(false);
    expect(isPlausiblePattern("abc]")).toBe(false);
  });
});

describe("codeowners-lint — validateCodeowners", () => {
  it("flags empty files as a warning", async () => {
    const r = await validateCodeowners("", allKnownResolver);
    expect(r.ok).toBe(true);
    expect(r.warnings).toHaveLength(1);
    expect(r.warnings[0].code).toBe("empty_file");
  });

  it("returns ok + a single info for a valid-but-missing-catchall file", async () => {
    const r = await validateCodeowners(
      "/docs/ @alice\n",
      resolver({ users: ["alice"] })
    );
    expect(r.errors).toHaveLength(0);
    expect(r.infos.some((f) => f.code === "missing_catchall")).toBe(true);
    expect(r.ok).toBe(true);
  });

  it("clean file with catchall yields zero findings", async () => {
    const r = await validateCodeowners(
      "* @alice\n",
      resolver({ users: ["alice"] })
    );
    expect(r.findings).toEqual([]);
    expect(r.ok).toBe(true);
  });

  it("catches pattern-with-no-owners", async () => {
    const r = await validateCodeowners(
      "* @alice\n/docs/\n",
      resolver({ users: ["alice"] })
    );
    const noOwners = r.findings.find((f) => f.code === "no_owners");
    expect(noOwners).toBeTruthy();
    expect(noOwners!.line).toBe(2);
    expect(r.ok).toBe(false);
  });

  it("reports unknown users", async () => {
    const r = await validateCodeowners(
      "* @ghost\n",
      noneKnownResolver
    );
    const unknown = r.findings.find((f) => f.code === "unknown_user");
    expect(unknown).toBeTruthy();
    expect(unknown!.token).toBe("ghost");
    expect(r.ok).toBe(false);
  });

  it("reports unknown teams", async () => {
    const r = await validateCodeowners(
      "* @acme/missing\n",
      resolver({})
    );
    const unknown = r.findings.find((f) => f.code === "unknown_team");
    expect(unknown).toBeTruthy();
    expect(unknown!.token).toBe("acme/missing");
  });

  it("accepts plain email owners without DB lookup", async () => {
    const r = await validateCodeowners(
      "* ops@example.com\n",
      noneKnownResolver
    );
    const errors = r.errors.filter(
      (f) =>
        f.code === "unknown_user" ||
        f.code === "unknown_team" ||
        f.code === "bad_owner_format"
    );
    expect(errors).toHaveLength(0);
    expect(r.ok).toBe(true);
  });

  it("flags bad owner formats", async () => {
    const r = await validateCodeowners(
      "* @-bad-user\n",
      allKnownResolver
    );
    const bad = r.findings.find((f) => f.code === "bad_owner_format");
    expect(bad).toBeTruthy();
  });

  it("flags duplicate patterns as warnings", async () => {
    const r = await validateCodeowners(
      "* @alice\n* @bob\n",
      resolver({ users: ["alice", "bob"] })
    );
    const dup = r.findings.find((f) => f.code === "duplicate_pattern");
    expect(dup).toBeTruthy();
    expect(dup!.severity).toBe("warning");
  });

  it("flags duplicate owners on the same rule as warnings", async () => {
    const r = await validateCodeowners(
      "* @alice @alice\n",
      resolver({ users: ["alice"] })
    );
    const dup = r.findings.find((f) => f.code === "duplicate_owner");
    expect(dup).toBeTruthy();
    expect(dup!.severity).toBe("warning");
  });

  it("orders findings by line number", async () => {
    const r = await validateCodeowners(
      "* @alice @alice\n/bad\n/docs/ @ghost\n",
      resolver({ users: ["alice"] })
    );
    const lines = r.findings.map((f) => f.line);
    const sorted = [...lines].sort((a, b) => a - b);
    expect(lines).toEqual(sorted);
  });

  it("returns ok=false when any error is present", async () => {
    const r = await validateCodeowners("/docs/\n", resolver({}));
    expect(r.ok).toBe(false);
  });

  it("returns ok=true when only warnings/infos exist", async () => {
    const r = await validateCodeowners(
      "/docs/ @alice\n",
      resolver({ users: ["alice"] })
    );
    expect(r.warnings.length + r.infos.length).toBeGreaterThan(0);
    expect(r.ok).toBe(true);
  });

  it("flags bad pattern syntax with unbalanced brackets", async () => {
    const r = await validateCodeowners(
      "[abc @alice\n",
      resolver({ users: ["alice"] })
    );
    const bad = r.findings.find((f) => f.code === "bad_pattern_syntax");
    expect(bad).toBeTruthy();
  });
});

describe("codeowners-lint — __internal parity", () => {
  it("re-exports the helpers", () => {
    expect(__internal.lexCodeowners).toBe(lexCodeowners);
    expect(__internal.classifyOwnerToken).toBe(classifyOwnerToken);
    expect(__internal.isPlausiblePattern).toBe(isPlausiblePattern);
    expect(__internal.validateCodeowners).toBe(validateCodeowners);
  });
});

describe("codeowners-lint — routes", () => {
  it("GET /:o/:r/codeowners returns 404 for unknown repos", async () => {
    const res = await app.request("/alice/nope/codeowners");
    expect(res.status).toBe(404);
  });
});