mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Skeleton
This commit is contained in:
parent
14bb6899d8
commit
2b0f8d9f0d
6 changed files with 76 additions and 4 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { ui } from "../src/environment/userInteraction.js";
|
import { ui } from "../src/environment/userInteraction.js";
|
||||||
import { setup } from "../src/shell-integration/setup.js";
|
import { setup } from "../src/shell-integration/setup.js";
|
||||||
import { teardown } from "../src/shell-integration/teardown.js";
|
import { teardown, teardownCi } from "../src/shell-integration/teardown.js";
|
||||||
import { setupCi } from "../src/shell-integration/setup-ci.js";
|
import { setupCi } from "../src/shell-integration/setup-ci.js";
|
||||||
import { initializeCliArguments } from "../src/config/cliArguments.js";
|
import { initializeCliArguments } from "../src/config/cliArguments.js";
|
||||||
import { setEcoSystem } from "../src/config/settings.js";
|
import { setEcoSystem } from "../src/config/settings.js";
|
||||||
|
|
@ -61,6 +61,7 @@ if (tool) {
|
||||||
setup();
|
setup();
|
||||||
} else if (command === "teardown") {
|
} else if (command === "teardown") {
|
||||||
teardown();
|
teardown();
|
||||||
|
teardownCi();
|
||||||
} else if (command === "setup-ci") {
|
} else if (command === "setup-ci") {
|
||||||
setupCi();
|
setupCi();
|
||||||
} else if (command === "--version" || command === "-v" || command === "-v") {
|
} else if (command === "--version" || command === "-v" || command === "-v") {
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,13 @@ export function getPackageManagerList() {
|
||||||
return `${tools.join(", ")}, and ${lastTool} commands`;
|
return `${tools.join(", ")}, and ${lastTool} commands`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function getShimsDir() {
|
||||||
|
return path.join(os.homedir(), ".safe-chain", "shims");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} executableName
|
* @param {string} executableName
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { ui } from "../environment/userInteraction.js";
|
import { ui } from "../environment/userInteraction.js";
|
||||||
import { getPackageManagerList, knownAikidoTools } from "./helpers.js";
|
import { getPackageManagerList, knownAikidoTools, getShimsDir } from "./helpers.js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
@ -32,7 +32,7 @@ export async function setupCi() {
|
||||||
);
|
);
|
||||||
ui.emptyLine();
|
ui.emptyLine();
|
||||||
|
|
||||||
const shimsDir = path.join(os.homedir(), ".safe-chain", "shims");
|
const shimsDir = getShimsDir();
|
||||||
const binDir = path.join(os.homedir(), ".safe-chain", "bin");
|
const binDir = path.join(os.homedir(), ".safe-chain", "bin");
|
||||||
// Create the shims directory if it doesn't exist
|
// Create the shims directory if it doesn't exist
|
||||||
if (!fs.existsSync(shimsDir)) {
|
if (!fs.existsSync(shimsDir)) {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ describe("Setup CI shell integration", () => {
|
||||||
{ tool: "yarn", aikidoCommand: "aikido-yarn" },
|
{ tool: "yarn", aikidoCommand: "aikido-yarn" },
|
||||||
],
|
],
|
||||||
getPackageManagerList: () => "npm, yarn",
|
getPackageManagerList: () => "npm, yarn",
|
||||||
|
getShimsDir: () => mockShimsDir,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { ui } from "../environment/userInteraction.js";
|
import { ui } from "../environment/userInteraction.js";
|
||||||
import { detectShells } from "./shellDetection.js";
|
import { detectShells } from "./shellDetection.js";
|
||||||
import { knownAikidoTools, getPackageManagerList } from "./helpers.js";
|
import { knownAikidoTools, getPackageManagerList, getShimsDir, } from "./helpers.js";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
|
|
@ -62,3 +63,24 @@ export async function teardown() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
export async function teardownCi() {
|
||||||
|
const shimsDir = getShimsDir();
|
||||||
|
if (fs.existsSync(shimsDir)) {
|
||||||
|
try {
|
||||||
|
fs.rmSync(shimsDir, { recursive: true, force: true });
|
||||||
|
ui.writeInformation(
|
||||||
|
`${chalk.bold("- CI Shims:")} ${chalk.green("Removed successfully")}`
|
||||||
|
);
|
||||||
|
} catch (/** @type {any} */ error) {
|
||||||
|
ui.writeError(
|
||||||
|
`${chalk.bold("- CI Shims:")} ${chalk.red(
|
||||||
|
"Failed to remove"
|
||||||
|
)}. Error: ${error.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
41
test/e2e/teardown-ci.e2e.spec.js
Normal file
41
test/e2e/teardown-ci.e2e.spec.js
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
import { describe, it, before, beforeEach, afterEach } from "node:test";
|
||||||
|
import { DockerTestContainer } from "./DockerTestContainer.js";
|
||||||
|
import assert from "node:assert";
|
||||||
|
|
||||||
|
describe("E2E: safe-chain teardown command (CI)", () => {
|
||||||
|
let container;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
DockerTestContainer.buildImage();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
container = new DockerTestContainer();
|
||||||
|
await container.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
if (container) {
|
||||||
|
await container.stop();
|
||||||
|
container = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("safe-chain teardown removes shims directory created by setup-ci", async () => {
|
||||||
|
const shell = await container.openShell("bash");
|
||||||
|
|
||||||
|
// Run setup-ci
|
||||||
|
await shell.runCommand("safe-chain setup-ci");
|
||||||
|
|
||||||
|
// Verify shims directory exists
|
||||||
|
const checkShimsExist = await shell.runCommand("test -d ~/.safe-chain/shims && echo 'exists' || echo 'missing'");
|
||||||
|
assert.ok(checkShimsExist.output.includes("exists"), "Shims directory should exist after setup-ci");
|
||||||
|
|
||||||
|
// Run teardown
|
||||||
|
await shell.runCommand("safe-chain teardown");
|
||||||
|
|
||||||
|
// Verify shims directory is gone
|
||||||
|
const checkShimsGone = await shell.runCommand("test -d ~/.safe-chain/shims && echo 'exists' || echo 'missing'");
|
||||||
|
assert.ok(checkShimsGone.output.includes("missing"), "Shims directory should be removed after teardown");
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue