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
dep-updater.test.ts8.3 KB · 286 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/**
 * Block D2 — AI dependency updater tests.
 *
 * Pure-function helpers are covered exhaustively. Route-level tests use
 * the standalone depUpdater router (the app-level mount is performed by
 * the main thread in `src/app.tsx`). They therefore tolerate the whole
 * class of graceful-degradation responses (302 / 404 / 503) that appear
 * when auth redirects or the DB isn't reachable.
 */

import { describe, it, expect } from "bun:test";
import {
  parseManifest,
  planUpdates,
  applyBumps,
} from "../lib/dep-updater";
import depUpdater from "../routes/dep-updater";

describe("parseManifest", () => {
  it("parses a valid package.json", () => {
    const json = JSON.stringify({
      name: "demo",
      dependencies: { hono: "^4.0.0" },
      devDependencies: { typescript: "^5.0.0" },
    });
    const m = parseManifest(json);
    expect(m.name).toBe("demo");
    expect(m.dependencies.hono).toBe("^4.0.0");
    expect(m.devDependencies.typescript).toBe("^5.0.0");
  });

  it("returns empty structures on invalid JSON", () => {
    const m = parseManifest("{ not valid ]");
    expect(m.dependencies).toEqual({});
    expect(m.devDependencies).toEqual({});
  });

  it("returns empty structures for empty input", () => {
    const m = parseManifest("");
    expect(m.dependencies).toEqual({});
    expect(m.devDependencies).toEqual({});
  });

  it("handles missing dependencies key gracefully", () => {
    const m = parseManifest(JSON.stringify({ name: "x" }));
    expect(m.dependencies).toEqual({});
    expect(m.devDependencies).toEqual({});
    expect(m.name).toBe("x");
  });

  it("ignores non-string dependency values", () => {
    const m = parseManifest(
      JSON.stringify({
        dependencies: { a: "1.0.0", b: 42, c: null, d: { foo: 1 } } as any,
      })
    );
    expect(m.dependencies.a).toBe("1.0.0");
    expect(m.dependencies.b).toBeUndefined();
    expect(m.dependencies.c).toBeUndefined();
    expect(m.dependencies.d).toBeUndefined();
  });
});

describe("planUpdates", () => {
  it("produces bumps for outdated packages", async () => {
    const fetchLatest = async (name: string) => {
      const map: Record<string, string> = {
        hono: "4.5.0",
        typescript: "5.4.2",
      };
      return map[name] ?? null;
    };
    const bumps = await planUpdates(
      {
        dependencies: { hono: "^4.0.0" },
        devDependencies: { typescript: "^5.0.0" },
      },
      { fetchLatest }
    );
    expect(bumps).toHaveLength(2);
    const hono = bumps.find((b) => b.name === "hono")!;
    expect(hono.from).toBe("^4.0.0");
    expect(hono.to).toBe("4.5.0");
    expect(hono.kind).toBe("dep");
    expect(hono.major).toBe(false);
    const ts = bumps.find((b) => b.name === "typescript")!;
    expect(ts.kind).toBe("dev");
  });

  it("no-ops when current version matches latest", async () => {
    const bumps = await planUpdates(
      {
        dependencies: { react: "^18.2.0" },
        devDependencies: {},
      },
      { fetchLatest: async () => "18.2.0" }
    );
    expect(bumps).toHaveLength(0);
  });

  it("skips downgrades", async () => {
    const bumps = await planUpdates(
      {
        dependencies: { foo: "^3.0.0" },
        devDependencies: {},
      },
      { fetchLatest: async () => "2.9.0" }
    );
    expect(bumps).toHaveLength(0);
  });

  it("skips non-semver ranges", async () => {
    const bumps = await planUpdates(
      {
        dependencies: {
          a: "workspace:*",
          b: "github:foo/bar",
          c: "file:./local",
          d: "*",
          e: "latest",
          f: "https://example.com/foo.tgz",
        },
        devDependencies: {},
      },
      { fetchLatest: async () => "9.9.9" }
    );
    expect(bumps).toHaveLength(0);
  });

  it("skips packages the registry doesn't return for", async () => {
    const bumps = await planUpdates(
      {
        dependencies: { missing: "^1.0.0" },
        devDependencies: {},
      },
      { fetchLatest: async () => null }
    );
    expect(bumps).toHaveLength(0);
  });

  it("flags major bumps", async () => {
    const bumps = await planUpdates(
      {
        dependencies: { hono: "^3.9.0" },
        devDependencies: {},
      },
      { fetchLatest: async () => "4.0.1" }
    );
    expect(bumps).toHaveLength(1);
    expect(bumps[0].major).toBe(true);
  });

  it("does not flag minor bumps as major", async () => {
    const bumps = await planUpdates(
      {
        dependencies: { hono: "^4.0.0" },
        devDependencies: {},
      },
      { fetchLatest: async () => "4.5.0" }
    );
    expect(bumps[0].major).toBe(false);
  });
});

describe("applyBumps", () => {
  it("rewrites the version of a single dep", () => {
    const input = `{
  "name": "demo",
  "dependencies": {
    "hono": "^4.0.0",
    "zod": "^3.22.0"
  }
}
`;
    const out = applyBumps(input, [
      { name: "hono", to: "4.5.0", kind: "dep" },
    ]);
    expect(out).toContain(`"hono": "^4.5.0"`);
    expect(out).toContain(`"zod": "^3.22.0"`);
    expect(out.endsWith("\n")).toBe(true);
  });

  it("preserves trailing newline exactly", () => {
    const input = `{"dependencies":{"a":"1.0.0"}}\n`;
    const out = applyBumps(input, [
      { name: "a", to: "1.0.1", kind: "dep" },
    ]);
    expect(out.endsWith("\n")).toBe(true);
    expect(out).toContain(`"a":"1.0.1"`);
  });

  it("preserves absence of trailing newline", () => {
    const input = `{"dependencies":{"a":"1.0.0"}}`;
    const out = applyBumps(input, [
      { name: "a", to: "1.0.1", kind: "dep" },
    ]);
    expect(out.endsWith("\n")).toBe(false);
  });

  it("does not touch devDependencies when bumping a dep", () => {
    const input = `{
  "dependencies": { "a": "^1.0.0" },
  "devDependencies": { "a": "^9.0.0" }
}
`;
    const out = applyBumps(input, [
      { name: "a", to: "1.5.0", kind: "dep" },
    ]);
    expect(out).toContain(`"dependencies": { "a": "^1.5.0" }`);
    expect(out).toContain(`"devDependencies": { "a": "^9.0.0" }`);
  });

  it("rewrites devDependencies when kind is dev", () => {
    const input = `{
  "dependencies": { "a": "^1.0.0" },
  "devDependencies": { "a": "^9.0.0" }
}
`;
    const out = applyBumps(input, [
      { name: "a", to: "9.5.0", kind: "dev" },
    ]);
    expect(out).toContain(`"dependencies": { "a": "^1.0.0" }`);
    expect(out).toContain(`"devDependencies": { "a": "^9.5.0" }`);
  });

  it("preserves the version prefix (^, ~, exact)", () => {
    const input = `{"dependencies":{"caret":"^1.0.0","tilde":"~2.0.0","exact":"3.0.0"}}\n`;
    const out = applyBumps(input, [
      { name: "caret", to: "1.5.0", kind: "dep" },
      { name: "tilde", to: "2.5.0", kind: "dep" },
      { name: "exact", to: "3.5.0", kind: "dep" },
    ]);
    expect(out).toContain(`"caret":"^1.5.0"`);
    expect(out).toContain(`"tilde":"~2.5.0"`);
    expect(out).toContain(`"exact":"3.5.0"`);
    expect(out).not.toContain(`"exact":"^3.5.0"`);
  });

  it("handles scoped package names", () => {
    const input = `{"dependencies":{"@scope/pkg":"^1.0.0"}}\n`;
    const out = applyBumps(input, [
      { name: "@scope/pkg", to: "1.1.0", kind: "dep" },
    ]);
    expect(out).toContain(`"@scope/pkg":"^1.1.0"`);
  });

  it("is a no-op when the stanza is missing", () => {
    const input = `{"name":"x"}\n`;
    const out = applyBumps(input, [
      { name: "nothing", to: "1.0.0", kind: "dep" },
    ]);
    expect(out).toBe(input);
  });
});

describe("routes/dep-updater", () => {
  it("GET without auth redirects to /login", async () => {
    const res = await depUpdater.request(
      "/alice/demo/settings/dep-updater",
      { redirect: "manual" }
    );
    // No session cookie + no bearer -> requireAuth redirects.
    expect([302, 303]).toContain(res.status);
    const loc = res.headers.get("location") || "";
    expect(loc).toContain("/login");
  });

  it("POST run without auth redirects to /login", async () => {
    const res = await depUpdater.request(
      "/alice/demo/settings/dep-updater/run",
      { method: "POST", redirect: "manual" }
    );
    expect([302, 303]).toContain(res.status);
    const loc = res.headers.get("location") || "";
    expect(loc).toContain("/login");
  });

  it("GET for a non-existent repo returns redirect or 404", async () => {
    const res = await depUpdater.request(
      "/nobody/nothing/settings/dep-updater",
      { redirect: "manual" }
    );
    // Unauthenticated -> redirect; authed-but-missing -> 404; DB down -> 503.
    expect([302, 303, 404, 503]).toContain(res.status);
  });
});