Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shellforge-ui",
"version": "1.0.2",
"version": "1.0.3",
"description": "ShellForge desktop manager for Windows PowerShell automation",
"author": "João Luiz de Castro",
"private": true,
Expand Down
42 changes: 42 additions & 0 deletions utils/tests/getConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const {
} = require("../getConfig");
const { getPackagedUserDataRoot } = require("../shellforgePaths");

const RUNTIME_ROOT = path.resolve(__dirname, "..", "..");
const RUNTIME_CONFIG_PATH = path.join(RUNTIME_ROOT, "config", "config.json");

function createTempRoot(prefix) {
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
}
Expand Down Expand Up @@ -43,6 +46,25 @@ function withSavedEnv(envKeys, runTest) {
};
}

function withRuntimeConfigBackup(runTest) {
const hadRuntimeConfig = fs.existsSync(RUNTIME_CONFIG_PATH);
const runtimeConfigBackup = hadRuntimeConfig
? fs.readFileSync(RUNTIME_CONFIG_PATH, "utf8")
: null;

return async () => {
try {
await runTest();
} finally {
if (hadRuntimeConfig && runtimeConfigBackup !== null) {
fs.writeFileSync(RUNTIME_CONFIG_PATH, runtimeConfigBackup, "utf8");
} else if (fs.existsSync(RUNTIME_CONFIG_PATH)) {
fs.unlinkSync(RUNTIME_CONFIG_PATH);
}
}
};
}

test("resolveUserDataRootFromInputs prefers envUserDataRoot when set", () => {
const envRoot = createTempRoot("shellforge-env-root-");

Expand Down Expand Up @@ -126,3 +148,23 @@ test(
assert.equal(resolveUserDataRoot(), path.resolve(envRoot));
})
);

test(
"resolveUserDataRoot wrapper uses AppData when runtime config is missing",
withSavedEnv(["SHELLFORGE_USER_DATA", "APPDATA"], async () => {
delete process.env.SHELLFORGE_USER_DATA;

const appDataRoot = createTempRoot("shellforge-wrapper-appdata-");
const packagedUserDataRoot = getPackagedUserDataRoot(appDataRoot);
writeConfigAtRoot(packagedUserDataRoot, '{"actionRunner":{}}');
process.env.APPDATA = appDataRoot;

await withRuntimeConfigBackup(async () => {
if (fs.existsSync(RUNTIME_CONFIG_PATH)) {
fs.unlinkSync(RUNTIME_CONFIG_PATH);
}

assert.equal(resolveUserDataRoot(), packagedUserDataRoot);
})();
})
);
Loading