refactor: extract working-directory validation into testable module

- Add src/working-directory.ts with validateWorkingDirectory()
- Add __test__/working-directory.test.ts with 4 test cases
- Update main.ts to use validation function
- Throw clear error for non-existent or non-directory paths
- Rebuild dist/index.js

Addresses review feedback on #426
This commit is contained in:
mehmet turac 2026-05-11 10:58:39 +03:00
parent 5ac99427a6
commit 7b9b30a1ea
No known key found for this signature in database
GPG key ID: 20D5F9AEE1833B0F
4 changed files with 99 additions and 4 deletions

27
dist/index.js vendored
View file

@ -65029,6 +65029,27 @@ function parseNumberArray(listString) {
// EXTERNAL MODULE: external "path"
var external_path_ = __nccwpck_require__(1017);
;// CONCATENATED MODULE: ./src/working-directory.ts
/**
* Validates that the given directory exists and is accessible.
* @param workingDirectory - The directory path to validate
* @returns The resolved absolute path
* @throws Error if the directory does not exist or is not a directory
*/
function validateWorkingDirectory(workingDirectory) {
const resolved = external_path_.resolve(workingDirectory);
if (!external_fs_.existsSync(resolved)) {
throw new Error(`working-directory "${workingDirectory}" does not exist (resolved to "${resolved}")`);
}
const stat = external_fs_.statSync(resolved);
if (!stat.isDirectory()) {
throw new Error(`working-directory "${workingDirectory}" is not a directory (resolved to "${resolved}")`);
}
return resolved;
}
;// CONCATENATED MODULE: ./src/wrap-require.ts
const wrapRequire = new Proxy(require, {
@ -65065,6 +65086,7 @@ const wrapRequire = new Proxy(require, {
process.on('unhandledRejection', handleError);
main().catch(handleError);
async function main() {
@ -65094,8 +65116,9 @@ async function main() {
const script = core.getInput('script', { required: true });
const workingDirectory = core.getInput('working-directory');
if (workingDirectory) {
core.info(`Changing working directory to ${workingDirectory}`);
process.chdir(workingDirectory);
const resolved = validateWorkingDirectory(workingDirectory);
core.info(`Changing working directory to ${resolved}`);
process.chdir(resolved);
}
// Wrap getOctokit so secondary clients inherit retry, logging,
// orchestration ID, and the action's retries input.