Merge branch 'main' into zsh-safe-chain-detection

This commit is contained in:
Sander Declerck 2025-07-18 15:15:38 +02:00
commit 6b1b21c670
No known key found for this signature in database
27 changed files with 672 additions and 224 deletions

View file

@ -3,6 +3,7 @@ import assert from "node:assert";
import { tmpdir } from "node:os";
import fs from "node:fs";
import path from "path";
import { knownAikidoTools } from "../helpers.js";
describe("Zsh shell integration", () => {
let mockStartupFile;
@ -15,7 +16,6 @@ describe("Zsh shell integration", () => {
// Mock the helpers module
mock.module("../helpers.js", {
namedExports: {
execAndGetOutput: () => mockStartupFile,
doesExecutableExistOnSystem: () => true,
addLineToFile: (filePath, line) => {
if (!fs.existsSync(filePath)) {
@ -33,6 +33,13 @@ describe("Zsh shell integration", () => {
},
});
// Mock child_process execSync
mock.module("child_process", {
namedExports: {
execSync: () => mockStartupFile,
},
});
// Import zsh module after mocking
zsh = (await import("./zsh.js")).default;
});
@ -71,22 +78,6 @@ describe("Zsh shell integration", () => {
);
});
it("should call teardown before setup", () => {
// Pre-populate file with existing source line
fs.writeFileSync(
mockStartupFile,
"source ~/.safe-chain/scripts/init-zsh.sh\n",
"utf-8"
);
zsh.setup();
const content = fs.readFileSync(mockStartupFile, "utf-8");
const sourceMatches = (content.match(/source.*init-zsh\.sh/g) || [])
.length;
assert.strictEqual(sourceMatches, 1, "Should not duplicate source lines");
});
it("should handle empty startup file", () => {
const result = zsh.setup();
assert.strictEqual(result, true);
@ -109,7 +100,7 @@ describe("Zsh shell integration", () => {
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
const result = zsh.teardown();
const result = zsh.teardown(knownAikidoTools);
assert.strictEqual(result, true);
const content = fs.readFileSync(mockStartupFile, "utf-8");
@ -142,7 +133,7 @@ describe("Zsh shell integration", () => {
fs.unlinkSync(mockStartupFile);
}
const result = zsh.teardown();
const result = zsh.teardown(knownAikidoTools);
assert.strictEqual(result, true);
});
@ -155,7 +146,7 @@ describe("Zsh shell integration", () => {
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
const result = zsh.teardown();
const result = zsh.teardown(knownAikidoTools);
assert.strictEqual(result, true);
const content = fs.readFileSync(mockStartupFile, "utf-8");
@ -179,20 +170,28 @@ describe("Zsh shell integration", () => {
describe("integration tests", () => {
it("should handle complete setup and teardown cycle", () => {
const tools = [
{ tool: "npm", aikidoCommand: "aikido-npm" },
{ tool: "yarn", aikidoCommand: "aikido-yarn" },
];
// Setup
zsh.setup();
let content = fs.readFileSync(mockStartupFile, "utf-8");
assert.ok(content.includes("source ~/.safe-chain/scripts/init-zsh.sh"));
// Teardown
zsh.teardown();
zsh.teardown(tools);
content = fs.readFileSync(mockStartupFile, "utf-8");
assert.ok(!content.includes("source ~/.safe-chain/scripts/init-zsh.sh"));
});
it("should handle multiple setup calls", () => {
zsh.setup();
zsh.setup();
const tools = [{ tool: "npm", aikidoCommand: "aikido-npm" }];
zsh.setup(tools);
zsh.teardown(tools);
zsh.setup(tools);
const content = fs.readFileSync(mockStartupFile, "utf-8");
const sourceMatches = (content.match(/source.*init-zsh\.sh/g) || [])