mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-08-28 05:25:25 +00:00
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / ci (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
* feat(setup): install Codex PreToolUse/PostToolUse hooks (#2328) Codex CLI supports lifecycle hooks with Claude Code's exact {hooks: {Event: [...]}} JSON schema, stdin payload, and hookSpecificOutput response contract, registered in a dedicated ~/.codex/hooks.json (https://developers.openai.com/codex/hooks). Parameterize installClaudeCodeHooks into installClaudeSchemaHooks (claude | codex): both runtimes share the installer, the bundled gitnexus-hook.cjs adapter, and its helpers. A codex HookTarget in editor-targets.ts makes uninstall and the setup-uninstall round-trip tripwire cover the new surface with no uninstall.ts changes. SessionStart is deliberately not registered: Codex reads AGENTS.md natively, which already carries the GitNexus context block. Closes #2328. Closes #244 (Codex setup support is now complete: MCP + skills + hooks). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(plugin): make the GitNexus plugin installable from Codex (#1131) Codex's plugin system (https://developers.openai.com/codex/plugins/build) reads a .codex-plugin/plugin.json manifest and a repo-root .agents/plugins/marketplace.json registry. The existing gitnexus-claude-plugin/ is already Codex-compatible as-is — Codex sets CLAUDE_PLUGIN_ROOT for hook-command compatibility, loads the same SKILL.md skills, hooks/hooks.json, and .mcp.json — so a second manifest in the same folder replaces PR #1131's duplicated plugin tree with zero copied skills or hooks. The .gitignore .agents/ scratch rule narrows to re-include only the registry file. Install: codex plugin marketplace add abhigyanpatwari/GitNexus Supersedes #1131. Co-authored-by: jublin <1799126+jublin@users.noreply.github.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs: document Codex full support (MCP + skills + hooks + plugin) Promote Codex to Full in both editor tables, document the ~/.codex/hooks.json hook install, and add the Codex plugin marketplace install path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(release): extend the version-lockstep guard to the Codex manifests The always-on drift guard asserted only the Claude plugin manifests against gitnexus/package.json, so a release could ship stale versions in .codex-plugin/plugin.json and .agents/plugins/marketplace.json without CI noticing. Mirror the Claude lockstep test for the two Codex files and extend the CONTRIBUTING §Releases lockstep list to match. Verified guard semantics: a deliberate local version mutation of the Codex marketplace entry turns the new test red. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(plugin): quote the hook command path for space-containing plugin roots Both plugin hook commands ran `node ${CLAUDE_PLUGIN_ROOT}/hooks/...` unquoted, which breaks whenever the substituted plugin root contains a space — the common case on Windows user profiles. Both Claude Code and Codex substitute the placeholder before shell execution, and Claude Code's plugin docs mandate the double-quoted form in shell-form hooks. No commandWindows entry: Codex source (codex-rs hooks engine) falls back to `command` on Windows with identical placeholder substitution, so an identical-content override would be pure duplication. Verified: space-in-root smoke test (old form exits 1 MODULE_NOT_FOUND, quoted form exits 0), `claude plugin validate` passes, and a local `codex plugin marketplace add` parses the marketplace + plugin cleanly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(setup): pin fail-closed behavior for unreadable/corrupt Codex hooks.json The non-ENOENT suite covered Claude settings.json (EACCES) and Codex config.toml (EACCES) but not the new ~/.codex/hooks.json surface, and the mergeHooksJsonc "is corrupt" branch had zero coverage for either editor. A future refactor dropping the isEnoent rethrow or the parse gate could silently rewrite a user's hooks.json gitnexus-only with no CI tripwire. Two regression tests: EACCES leaves hooks.json byte-identical and reports "Codex hooks: EACCES"; corrupt content is preserved and reported via "Codex hooks: hooks.json is corrupt". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(readme): add the Codex plugin-marketplace install path to the npm README The root README documents the one-step plugin route but the package README (what npmjs.com renders) only showed the setup-CLI path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor(setup): rename claudeHook to hookCfg in installClaudeSchemaHooks The local held a codex HookTarget on the codex branch since the installer was parameterized, so the claude-specific name misled. Pure local rename, no behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(readme): document Codex SessionStart exclusion, /hooks trust gate, and install-route choice Three behaviors were only recorded in code comments and the PR body: SessionStart is deliberately not registered (Codex reads AGENTS.md natively), setup-installed hooks need one-time /hooks approval in Codex, and the setup CLI and plugin are alternative install routes whose hooks load alongside each other if both are used. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor(test): share one logLines helper across setup.test.ts describes The corrupt-hooks.json test inlined the console.log-flattening expression that the non-ENOENT describe already defined locally. Hoist a single file-scope logLines so the two stay in sync. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
220 lines
10 KiB
TypeScript
220 lines
10 KiB
TypeScript
import fs from 'node:fs/promises';
|
||
import path from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
import { describe, it, expect, vi } from 'vitest';
|
||
|
||
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
|
||
|
||
async function readRepoJson<T>(relativePath: string): Promise<T> {
|
||
return JSON.parse(await fs.readFile(path.join(REPO_ROOT, relativePath), 'utf8')) as T;
|
||
}
|
||
|
||
// Mock all the heavy imports before importing index
|
||
vi.mock('../../src/cli/analyze.js', () => ({
|
||
analyzeCommand: vi.fn(),
|
||
}));
|
||
vi.mock('../../src/cli/mcp.js', () => ({
|
||
mcpCommand: vi.fn(),
|
||
}));
|
||
vi.mock('../../src/cli/setup.js', () => ({
|
||
setupCommand: vi.fn(),
|
||
}));
|
||
vi.mock('../../src/cli/publish.js', () => ({
|
||
publishCommand: vi.fn(),
|
||
}));
|
||
|
||
describe('CLI commands', () => {
|
||
describe('version', () => {
|
||
it('package.json has a valid version string', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
expect(pkg.default.version).toMatch(/^\d+\.\d+\.\d+/);
|
||
});
|
||
|
||
it('keeps Claude plugin manifests aligned with the gitnexus release version', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
const pluginManifest = await readRepoJson<{ version: string }>(
|
||
'gitnexus-claude-plugin/.claude-plugin/plugin.json',
|
||
);
|
||
const marketplaceManifest = await readRepoJson<{
|
||
plugins?: Array<{ name: string; version: string }>;
|
||
}>('.claude-plugin/marketplace.json');
|
||
|
||
expect(Array.isArray(marketplaceManifest.plugins)).toBe(true);
|
||
|
||
const gitnexusEntries = (marketplaceManifest.plugins ?? []).filter(
|
||
(plugin) => plugin.name === 'gitnexus',
|
||
);
|
||
|
||
expect(gitnexusEntries).toHaveLength(1);
|
||
expect(pluginManifest.version).toBe(pkg.default.version);
|
||
expect(gitnexusEntries[0]?.version).toBe(pkg.default.version);
|
||
});
|
||
|
||
it('keeps Codex plugin manifests aligned with the gitnexus release version', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
const pluginManifest = await readRepoJson<{ version: string }>(
|
||
'gitnexus-claude-plugin/.codex-plugin/plugin.json',
|
||
);
|
||
const marketplaceManifest = await readRepoJson<{
|
||
plugins?: Array<{ name: string; version: string }>;
|
||
}>('.agents/plugins/marketplace.json');
|
||
|
||
expect(Array.isArray(marketplaceManifest.plugins)).toBe(true);
|
||
|
||
const gitnexusEntries = (marketplaceManifest.plugins ?? []).filter(
|
||
(plugin) => plugin.name === 'gitnexus',
|
||
);
|
||
|
||
expect(gitnexusEntries).toHaveLength(1);
|
||
expect(pluginManifest.version).toBe(pkg.default.version);
|
||
expect(gitnexusEntries[0]?.version).toBe(pkg.default.version);
|
||
});
|
||
});
|
||
|
||
describe('package.json scripts', () => {
|
||
it('has test scripts configured', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
expect(pkg.default.scripts.test).toBeDefined();
|
||
expect(pkg.default.scripts['test:integration']).toBeDefined();
|
||
expect(pkg.default.scripts['test:unit']).toBeDefined();
|
||
});
|
||
|
||
it('has build script', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
expect(pkg.default.scripts.build).toBeDefined();
|
||
});
|
||
});
|
||
|
||
describe('package.json bin entry', () => {
|
||
it('exposes gitnexus binary', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
expect(pkg.default.bin).toBeDefined();
|
||
expect(pkg.default.bin.gitnexus || pkg.default.bin).toBeDefined();
|
||
});
|
||
});
|
||
|
||
describe('optional parser dependencies', () => {
|
||
it('loads vendored grammars from vendor/ — never file: optionalDependencies (#1728) nor a node_modules copy (#2111)', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
const optional = pkg.default.optionalDependencies ?? {};
|
||
expect(optional['tree-sitter-dart']).toBeUndefined();
|
||
expect(optional['tree-sitter-proto']).toBeUndefined();
|
||
expect(optional['tree-sitter-swift']).toBeUndefined();
|
||
// #2111: the grammars MUST NOT be copied into node_modules at install — an
|
||
// undeclared node_modules package is "extraneous" to every subsequent
|
||
// npm/npx reify, which prunes/relocates it (Windows EPERM symlink + silent
|
||
// deletion on the 2nd run). They are loaded from vendor/ by absolute path
|
||
// (vendored-grammars.ts), so postinstall no longer materializes anything.
|
||
expect(pkg.default.scripts.postinstall).not.toContain('materialize-vendor-grammars.cjs');
|
||
expect(pkg.default.scripts.postinstall).toContain('build-tree-sitter-grammars.cjs');
|
||
expect(pkg.default.files).toContain('vendor');
|
||
});
|
||
|
||
it('declares node-gyp-build/node-addon-api as regular dependencies (runtime-load contract)', async () => {
|
||
// Every vendored grammar's index.js does `require("node-gyp-build")` at
|
||
// runtime to load even a prebuilt .node, so node-gyp-build must always be
|
||
// present. They were optionalDependencies (surviving --omit=optional only
|
||
// via tree-sitter's transitive edge); promote them so the contract is
|
||
// explicit and robust to a future tree-sitter change.
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
const deps = pkg.default.dependencies ?? {};
|
||
const optional = (pkg.default as { optionalDependencies?: Record<string, string> })
|
||
.optionalDependencies;
|
||
expect(deps['node-gyp-build']).toBeDefined();
|
||
expect(deps['node-addon-api']).toBeDefined();
|
||
// No grammar/native-build entries linger in optionalDependencies.
|
||
expect(optional?.['node-gyp-build']).toBeUndefined();
|
||
expect(optional?.['node-addon-api']).toBeUndefined();
|
||
});
|
||
|
||
it('keeps vendored Swift runtime with vendored source + GitNexus-built prebuilds and hoisted activation script', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
const swiftPkg = await import('../../vendor/tree-sitter-swift/package.json', {
|
||
with: { type: 'json' },
|
||
});
|
||
// Exact pin (no caret) — #1922 holds the runtime at 0.21.1 so the ABI
|
||
// gate's assumptions (setTimeoutMicros semantics, ABI 13–14 grammar
|
||
// range) can't drift under a minor bump.
|
||
expect(pkg.default.dependencies['tree-sitter']).toBe('0.21.1');
|
||
expect(pkg.default.scripts.postinstall).toContain('build-tree-sitter-grammars.cjs');
|
||
expect(swiftPkg.default.version).toBe('0.7.1');
|
||
// No scripts.install / dependencies inside vendor/ (#836 / #1728 hygiene).
|
||
expect(swiftPkg.default.scripts?.install).toBeUndefined();
|
||
expect(swiftPkg.default.dependencies).toBeUndefined();
|
||
expect(swiftPkg.default.peerDependencies['tree-sitter']).toContain('^0.21.1');
|
||
// Swift is now unified with Dart/Proto/Kotlin/C: the grammar SOURCE is
|
||
// vendored so build-tree-sitter-grammars.cjs can source-build the binding
|
||
// when no committed prebuild matches (e.g. CI before prebuilds land).
|
||
const bindingGyp = await fs.readFile(
|
||
path.join(REPO_ROOT, 'gitnexus/vendor/tree-sitter-swift/binding.gyp'),
|
||
'utf8',
|
||
);
|
||
expect(bindingGyp).toContain('tree_sitter_swift_binding');
|
||
expect(bindingGyp).toContain('src/parser.c');
|
||
await expect(
|
||
fs.stat(path.join(REPO_ROOT, 'gitnexus/vendor/tree-sitter-swift/src/parser.c')),
|
||
).resolves.toBeDefined();
|
||
});
|
||
|
||
it('keeps vendored Kotlin runtime with GitNexus-built prebuilds and hoisted activation script (#2107)', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
const kotlinPkg = await import('../../vendor/tree-sitter-kotlin/package.json', {
|
||
with: { type: 'json' },
|
||
});
|
||
const optional = pkg.default.optionalDependencies ?? {};
|
||
// Kotlin is now VENDORED (like Swift/Dart/Proto), not a third-party npm
|
||
// optionalDependency. Its prebuilds are GitNexus-cross-built (upstream
|
||
// ships source only) and loaded from vendor/ by absolute path (#2111).
|
||
expect(optional['tree-sitter-kotlin']).toBeUndefined();
|
||
expect(pkg.default.scripts.postinstall).toContain('build-tree-sitter-grammars.cjs');
|
||
expect(kotlinPkg.default.version).toBe('0.4.0');
|
||
// No scripts.install / dependencies inside vendor/ (#836 / #1728 hygiene).
|
||
expect(kotlinPkg.default.scripts?.install).toBeUndefined();
|
||
expect(kotlinPkg.default.dependencies).toBeUndefined();
|
||
expect(kotlinPkg.default.peerDependencies['tree-sitter']).toContain('^0.21');
|
||
});
|
||
|
||
it('vendors tree-sitter-c prebuild-only at the 0.21.4 ABI pin instead of an npm dependency (#2116/#1242)', async () => {
|
||
const pkg = await import('../../package.json', { with: { type: 'json' } });
|
||
const cPkg = await import('../../vendor/tree-sitter-c/package.json', {
|
||
with: { type: 'json' },
|
||
});
|
||
// c is a REQUIRED grammar that hard-fails install on toolchain-less ARM
|
||
// (upstream ships 4/6). Vendored with GitNexus-built prebuilds for all 6,
|
||
// held at 0.21.4 for ABI safety (#1242) — so it is NOT an npm dependency.
|
||
expect(pkg.default.dependencies['tree-sitter-c']).toBeUndefined();
|
||
expect(pkg.default.scripts.postinstall).toContain('build-tree-sitter-grammars.cjs');
|
||
expect(cPkg.default.version).toBe('0.21.4');
|
||
expect(cPkg.default.scripts?.install).toBeUndefined();
|
||
expect(cPkg.default.dependencies).toBeUndefined();
|
||
});
|
||
});
|
||
|
||
describe('analyzeCommand', () => {
|
||
it('is a function', async () => {
|
||
const { analyzeCommand } = await import('../../src/cli/analyze.js');
|
||
expect(typeof analyzeCommand).toBe('function');
|
||
});
|
||
});
|
||
|
||
describe('mcpCommand', () => {
|
||
it('is a function', async () => {
|
||
const { mcpCommand } = await import('../../src/cli/mcp.js');
|
||
expect(typeof mcpCommand).toBe('function');
|
||
});
|
||
});
|
||
|
||
describe('setupCommand', () => {
|
||
it('is a function', async () => {
|
||
const { setupCommand } = await import('../../src/cli/setup.js');
|
||
expect(typeof setupCommand).toBe('function');
|
||
});
|
||
});
|
||
|
||
describe('publishCommand', () => {
|
||
it('is a function', async () => {
|
||
const { publishCommand } = await import('../../src/cli/publish.js');
|
||
expect(typeof publishCommand).toBe('function');
|
||
});
|
||
});
|
||
});
|