@wonsukchoi/crondex 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ // Pure logic behind scripts/smoke-test.js: resolving a job's command with its real
2
+ // default variable values, and wrapping it for sandboxed execution. Split out so the
3
+ // resolution step is unit testable without actually spawning a shell.
4
+ import { substitutePlaceholders } from "./deploy.js";
5
+
6
+ // Unlike lint-shell.js (which stands placeholders in as bash variables to run
7
+ // shellcheck's static analysis), this resolves them exactly like a real deployment
8
+ // would — using each variable's actual `default` — so the smoke test exercises the
9
+ // real behavior a user would get, not a synthetic stand-in.
10
+ export function resolveJobCommand(job) {
11
+ const values = {};
12
+ for (const [name, spec] of Object.entries(job.variables ?? {})) values[name] = spec.default;
13
+ return substitutePlaceholders(job.command, values);
14
+ }
15
+
16
+ // Wraps a resolved command for sandboxed execution:
17
+ // - `set -u` so an unbound variable (a real bug) aborts instead of silently
18
+ // expanding to empty string.
19
+ // - HOME repointed into the sandbox dir, so a job whose default touches
20
+ // "$HOME/..." (e.g. downloads-folder-auto-organize) can't reach the real user's
21
+ // home directory.
22
+ // - a `command_not_found_handle` fallback so any external tool not installed on
23
+ // this machine (aws, gh, kubectl, redis-cli, ...) resolves to a harmless no-op
24
+ // instead of a hard "command not found" — this lets the job's own control flow
25
+ // run for real without requiring every possible external tool to be present.
26
+ export function buildSandboxScript(resolvedCommand) {
27
+ return [
28
+ "set -u",
29
+ "command_not_found_handle() { return 0; }",
30
+ resolvedCommand,
31
+ ].join("\n");
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wonsukchoi/crondex",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "A public directory of pre-made, agent-editable cron jobs.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,6 +36,7 @@
36
36
  "validate": "node scripts/validate-jobs.js",
37
37
  "lint-shell": "node scripts/lint-shell.js",
38
38
  "check-duplicates": "node scripts/check-duplicates.js",
39
+ "smoke-test": "node scripts/smoke-test.js",
39
40
  "test": "node --test"
40
41
  },
41
42
  "dependencies": {