mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Also remove script dir
This commit is contained in:
parent
7e88490bd1
commit
a405a51706
5 changed files with 53 additions and 8 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, teardownCi } from "../src/shell-integration/teardown.js";
|
import { teardown, teardownDirectories } 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";
|
||||||
|
|
@ -60,7 +60,7 @@ if (tool) {
|
||||||
} else if (command === "setup") {
|
} else if (command === "setup") {
|
||||||
setup();
|
setup();
|
||||||
} else if (command === "teardown") {
|
} else if (command === "teardown") {
|
||||||
teardownCi();
|
teardownDirectories();
|
||||||
teardown();
|
teardown();
|
||||||
} else if (command === "setup-ci") {
|
} else if (command === "setup-ci") {
|
||||||
setupCi();
|
setupCi();
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,13 @@ export function getShimsDir() {
|
||||||
return path.join(os.homedir(), ".safe-chain", "shims");
|
return path.join(os.homedir(), ".safe-chain", "shims");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function getScriptsDir() {
|
||||||
|
return path.join(os.homedir(), ".safe-chain", "scripts");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} executableName
|
* @param {string} executableName
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
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, getScriptsDir } 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";
|
||||||
|
|
@ -107,10 +107,10 @@ function setupShell(shell) {
|
||||||
|
|
||||||
function copyStartupFiles() {
|
function copyStartupFiles() {
|
||||||
const startupFiles = ["init-posix.sh", "init-pwsh.ps1", "init-fish.fish"];
|
const startupFiles = ["init-posix.sh", "init-pwsh.ps1", "init-fish.fish"];
|
||||||
|
const targetDir = getScriptsDir();
|
||||||
|
|
||||||
for (const file of startupFiles) {
|
for (const file of startupFiles) {
|
||||||
const targetDir = path.join(os.homedir(), ".safe-chain", "scripts");
|
const targetPath = path.join(targetDir, file);
|
||||||
const targetPath = path.join(os.homedir(), ".safe-chain", "scripts", file);
|
|
||||||
|
|
||||||
if (!fs.existsSync(targetDir)) {
|
if (!fs.existsSync(targetDir)) {
|
||||||
fs.mkdirSync(targetDir, { recursive: true });
|
fs.mkdirSync(targetDir, { recursive: true });
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
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, getShimsDir, } from "./helpers.js";
|
import { knownAikidoTools, getPackageManagerList, getShimsDir, getScriptsDir } from "./helpers.js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -65,10 +65,14 @@ export async function teardown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Removes directories created by setup-ci and setup commands
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
export async function teardownCi() {
|
export async function teardownDirectories() {
|
||||||
const shimsDir = getShimsDir();
|
const shimsDir = getShimsDir();
|
||||||
|
const scriptsDir = getScriptsDir();
|
||||||
|
|
||||||
|
// Remove CI shims directory
|
||||||
if (fs.existsSync(shimsDir)) {
|
if (fs.existsSync(shimsDir)) {
|
||||||
try {
|
try {
|
||||||
fs.rmSync(shimsDir, { recursive: true, force: true });
|
fs.rmSync(shimsDir, { recursive: true, force: true });
|
||||||
|
|
@ -83,4 +87,20 @@ export async function teardownCi() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove scripts directory
|
||||||
|
if (fs.existsSync(scriptsDir)) {
|
||||||
|
try {
|
||||||
|
fs.rmSync(scriptsDir, { recursive: true, force: true });
|
||||||
|
ui.writeInformation(
|
||||||
|
`${chalk.bold("- Scripts:")} ${chalk.green("Removed successfully")}`
|
||||||
|
);
|
||||||
|
} catch (/** @type {any} */ error) {
|
||||||
|
ui.writeError(
|
||||||
|
`${chalk.bold("- Scripts:")} ${chalk.red(
|
||||||
|
"Failed to remove"
|
||||||
|
)}. Error: ${error.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { describe, it, before, beforeEach, afterEach } from "node:test";
|
||||||
import { DockerTestContainer } from "./DockerTestContainer.js";
|
import { DockerTestContainer } from "./DockerTestContainer.js";
|
||||||
import assert from "node:assert";
|
import assert from "node:assert";
|
||||||
|
|
||||||
describe("E2E: safe-chain teardown command (CI)", () => {
|
describe("E2E: safe-chain teardown command", () => {
|
||||||
let container;
|
let container;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
|
@ -38,4 +38,22 @@ describe("E2E: safe-chain teardown command (CI)", () => {
|
||||||
const checkShimsGone = await shell.runCommand("test -d ~/.safe-chain/shims && echo 'exists' || echo 'missing'");
|
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");
|
assert.ok(checkShimsGone.output.includes("missing"), "Shims directory should be removed after teardown");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("safe-chain teardown removes scripts directory created by setup", async () => {
|
||||||
|
const shell = await container.openShell("bash");
|
||||||
|
|
||||||
|
// Run setup
|
||||||
|
await shell.runCommand("safe-chain setup");
|
||||||
|
|
||||||
|
// Verify scripts directory exists
|
||||||
|
const checkScriptsExist = await shell.runCommand("test -d ~/.safe-chain/scripts && echo 'exists' || echo 'missing'");
|
||||||
|
assert.ok(checkScriptsExist.output.includes("exists"), "Scripts directory should exist after setup");
|
||||||
|
|
||||||
|
// Run teardown
|
||||||
|
await shell.runCommand("safe-chain teardown");
|
||||||
|
|
||||||
|
// Verify scripts directory is gone
|
||||||
|
const checkScriptsGone = await shell.runCommand("test -d ~/.safe-chain/scripts && echo 'exists' || echo 'missing'");
|
||||||
|
assert.ok(checkScriptsGone.output.includes("missing"), "Scripts directory should be removed after teardown");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue