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
action-registry.test.ts5.7 KB · 181 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
/**
 * Unit tests for src/lib/action-registry.ts (Agent 8, Sprint 1).
 *
 * Covers the in-memory registry resolution logic and the two simplest
 * built-ins (checkout, gatetest) that can be exercised without hitting the
 * filesystem or a real backend. The cache/upload/download actions all spawn
 * `tar` and talk to Agent 6's helper module; they're out of scope here
 * (they're integration-shaped and better served by integration tests).
 *
 * The `gatetest` handler calls `db.select()` to resolve owner/repo. We stub
 * `../db` via `mock.module` the same way `repo-access.test.ts` does, so the
 * test stays deterministic without real Postgres.
 */

import { describe, it, expect, mock, afterAll } from "bun:test";

// Stub the DB module before importing the registry.
let _lastFrom: any = null;
let _nextRepoRow: { name: string; ownerId: string } | undefined;
let _nextUserRow: { username: string } | undefined;

const _chain: any = {
  from: (table: any) => {
    _lastFrom = table;
    return _chain;
  },
  where: () => _chain,
  leftJoin: () => _chain,
  innerJoin: () => _chain,
  orderBy: () => _chain,
  limit: async () => {
    const t = _lastFrom;
    if (t && typeof t === "object") {
      if ("username" in t && "passwordHash" in t) {
        return _nextUserRow ? [_nextUserRow] : [];
      }
      if ("ownerId" in t && "name" in t) {
        return _nextRepoRow ? [_nextRepoRow] : [];
      }
    }
    return [];
  },
  set: () => _chain,
};

const _fakeDb = {
  db: {
    select: () => _chain,
    insert: () => _chain,
    update: () => _chain,
    delete: () => _chain,
  },
  getDb: () => ({
    select: () => _chain,
    insert: () => _chain,
    update: () => _chain,
    delete: () => _chain,
  }),
};
mock.module("../db", () => _fakeDb);

afterAll(() => {
  _nextRepoRow = undefined;
  _nextUserRow = undefined;
  _lastFrom = null;
});

// Import AFTER the mock is registered so the registry's built-ins see the
// stub DB when they pull in `../db`.
import {
  resolveAction,
  listActions,
  registerAction,
} from "../lib/action-registry";

const ORIGINAL_GATETEST_URL = process.env.GATETEST_URL;
function clearGatetestUrl() {
  delete process.env.GATETEST_URL;
}
function restoreGatetestUrl() {
  if (ORIGINAL_GATETEST_URL === undefined) delete process.env.GATETEST_URL;
  else process.env.GATETEST_URL = ORIGINAL_GATETEST_URL;
}

afterAll(() => {
  restoreGatetestUrl();
});

const ACTION_CTX_BASE = {
  with: {},
  env: {},
  workspace: "/tmp/fake-workspace",
  runId: "run-id",
  jobId: "job-id",
  repoId: "repo-id",
  commitSha: "deadbeef",
  ref: "refs/heads/main",
};

describe("action-registry — resolveAction", () => {
  it("resolves gluecron/checkout@v1 to the checkout handler", () => {
    const h = resolveAction("gluecron/checkout@v1");
    expect(h).not.toBeNull();
    expect(h?.name).toBe("gluecron/checkout");
    expect(h?.version).toBe("v1");
  });

  it("resolves gluecron/gatetest@v1 to the gatetest handler", () => {
    const h = resolveAction("gluecron/gatetest@v1");
    expect(h).not.toBeNull();
    expect(h?.name).toBe("gluecron/gatetest");
    expect(h?.version).toBe("v1");
  });

  it("resolveAction('unknown/foo@v1') returns null", () => {
    const h = resolveAction("unknown/foo@v1");
    expect(h).toBeNull();
  });

  it("resolveAction('gluecron/checkout') with no @version resolves to the default (v1)", () => {
    const h = resolveAction("gluecron/checkout");
    expect(h).not.toBeNull();
    expect(h?.name).toBe("gluecron/checkout");
    expect(h?.version).toBe("v1");
  });

  it("listActions() includes all 5 built-ins", () => {
    const names = listActions().map((a) => a.name);
    expect(names).toContain("gluecron/checkout");
    expect(names).toContain("gluecron/gatetest");
    expect(names).toContain("gluecron/cache");
    expect(names).toContain("gluecron/upload-artifact");
    expect(names).toContain("gluecron/download-artifact");
  });

  it("registerAction de-duplicates repeated registrations of the same name@version", () => {
    // Use a dedicated test-only name so we don't clobber a built-in.
    const before = listActions().length;
    const handler = {
      name: "gluecron/__test_dedupe__",
      version: "v1",
      async run() {
        return { exitCode: 0 };
      },
    };
    registerAction(handler);
    const afterFirst = listActions().length;
    registerAction(handler);
    const afterSecond = listActions().length;
    expect(afterFirst).toBe(before + 1);
    expect(afterSecond).toBe(afterFirst);
  });
});

describe("action-registry — built-in behaviour", () => {
  it("checkout.run() returns exitCode 0 and emits the sha output", async () => {
    const h = resolveAction("gluecron/checkout@v1")!;
    const res = await h.run({ ...ACTION_CTX_BASE });
    expect(res.exitCode).toBe(0);
    expect(res.outputs?.sha).toBe("deadbeef");
  });

  it("gatetest.run() handles missing repo lookup gracefully (returns non-zero with stderr)", async () => {
    // The config getter provides a default GATETEST_URL, so we exercise the
    // realistic path: the action tries to look up the repo. Our DB stub
    // returns no rows, so the handler reports an unresolved-repo error but
    // never throws — the key contract is "handler returns a result object".
    _nextRepoRow = undefined;
    _nextUserRow = undefined;
    const h = resolveAction("gluecron/gatetest@v1")!;
    const res = await h.run({ ...ACTION_CTX_BASE });
    expect(typeof res.exitCode).toBe("number");
    // With no repo row, the handler emits a 'unable to resolve' stderr on 1
    // OR a 'GateTest: ...' result on 0 if a fallback path was taken. Either
    // way, we expect a structured object (never throws).
    expect(res).toBeDefined();
    if (res.exitCode !== 0) {
      expect((res.stderr || "").length).toBeGreaterThan(0);
    }
  });
});