Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
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
push-policy-newbranch-scan.test.ts4.5 KB · 105 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
/**
 * Regression: the pre-receive secret scan must inspect ONLY what a push
 * actually introduces — not the entire repo tree.
 *
 * The bug: for a NEW branch (oldSha = zero-SHA), buildPreReceiveScript() used
 * LOG_RANGE="$NEW" and a `git diff <empty-tree> $NEW`, which reports every
 * file in the whole repo as "changed". So pushing a clean feature branch was
 * rejected because a PRE-EXISTING committed test fixture (crafted to look like
 * a real secret, to test the scanner itself) matched a pattern — even though
 * the branch never touched it. This broke the documented
 * "push a feature branch → open a PR" workflow for every new branch.
 *
 * These tests drive the ACTUAL generated hook via a real `git push` into a
 * bare repo (same as production), rather than re-implementing the range logic.
 */
import { describe, expect, it, beforeAll } from "bun:test";
import { mkdtempSync, writeFileSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
import { installPackInspectionHook } from "../lib/push-policy";

// A realistic-looking AWS key SHAPE used only to drive the scanner in the
// temp repo below. The `fake` marker on this line makes the push-time secret
// scanner's placeholder filter skip THIS source line, while the value still
// matches inside the generated fixture files (whose lines carry no marker).
const FIXTURE_SECRET = "AKIAABCDEFGH1234IJKL"; // fake test credential, not real

function git(cwd: string, args: string[], allowFail = false) {
  const proc = Bun.spawnSync(["git", ...args], {
    cwd,
    env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
  });
  const exitCode = proc.exitCode;
  const stderr = new TextDecoder().decode(proc.stderr);
  if (!allowFail && exitCode !== 0) {
    throw new Error(`git ${args.join(" ")} failed (${exitCode}):\n${stderr}`);
  }
  return { exitCode, stderr, stdout: new TextDecoder().decode(proc.stdout) };
}

const GIT_OK = (() => {
  try {
    return Bun.spawnSync(["git", "--version"]).exitCode === 0;
  } catch {
    return false;
  }
})();

describe.skipIf(!GIT_OK)("pre-receive scan only inspects pushed changes", () => {
  let bare: string;
  let work: string;

  beforeAll(async () => {
    const root = mkdtempSync(join(tmpdir(), "gc-newbranch-"));
    bare = join(root, "bare.git");
    work = join(root, "work");

    git(root, ["init", "--bare", "-b", "main", bare]);
    git(root, ["init", "-b", "main", work]);
    git(work, ["config", "user.email", "t@example.com"]);
    git(work, ["config", "user.name", "Test"]);
    git(work, ["config", "commit.gpgsign", "false"]);

    // Seed main with a pre-existing fixture that CONTAINS a secret pattern,
    // pushed BEFORE the hook is installed (so it lands, exactly like the real
    // fixtures that predate the scanner).
    writeFileSync(join(work, "fixture.ts"), `const K = '${FIXTURE_SECRET}';\n`);
    git(work, ["add", "."]);
    git(work, ["commit", "-m", "seed fixture (has a secret pattern)"]);
    git(work, ["remote", "add", "origin", bare]);
    git(work, ["push", "-u", "origin", "main"]);

    // Now arm the pre-receive hook on the bare repo.
    const hook = await installPackInspectionHook([], { secretScan: true });
    if (!hook) throw new Error("hook install returned null");
    git(bare, ["config", "core.hooksPath", hook.env.GIT_CONFIG_VALUE_0]);
  });

  it("accepts a new branch that only adds a clean file (does NOT rescan the pre-existing fixture)", () => {
    git(work, ["checkout", "-b", "clean-feature", "main"]);
    writeFileSync(join(work, "clean.ts"), "export const ok = 1;\n");
    git(work, ["add", "clean.ts"]);
    git(work, ["commit", "-m", "add a clean file"]);

    const res = git(work, ["push", "origin", "clean-feature"], true);
    // Before the fix this failed with "Secret scan: possible AWS Access Key
    // in fixture.ts" — a file the branch never touched.
    expect(res.stderr).not.toContain("Secret scan");
    expect(res.exitCode).toBe(0);
  });

  it("still blocks a new branch that itself introduces a real secret", () => {
    git(work, ["checkout", "-b", "leaky-feature", "main"]);
    writeFileSync(join(work, "leak.ts"), `const K = '${FIXTURE_SECRET}';\n`);
    git(work, ["add", "leak.ts"]);
    git(work, ["commit", "-m", "oops committed a secret"]);

    const res = git(work, ["push", "origin", "leaky-feature"], true);
    expect(res.exitCode).not.toBe(0);
    expect(res.stderr).toContain("Secret scan");
    expect(res.stderr).toContain("leak.ts");
    // And it must NOT also (falsely) flag the untouched fixture.
    expect(res.stderr).not.toContain("fixture.ts");
  });
});