@tenonhq/dovetail-core 0.0.129 → 0.0.131

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,81 @@
1
+ "use strict";
2
+ // The exit hook in a REAL Node process (#185).
3
+ //
4
+ // authFailure.test.ts checks installAuthExitCode against a hand-built fake `proc`,
5
+ // which would still pass if Node ignored an `exitCode` set inside an `exit`
6
+ // listener. These tests spawn `node`, install the hook on the real `process`, and
7
+ // assert the status the parent actually sees.
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const child_process_1 = require("child_process");
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const os_1 = __importDefault(require("os"));
15
+ const path_1 = __importDefault(require("path"));
16
+ const typescript_1 = __importDefault(require("typescript"));
17
+ var RUNNER = [
18
+ '"use strict";',
19
+ 'var auth = require("./authFailure.js");',
20
+ "auth.installAuthExitCode(process);",
21
+ "var mode = process.argv[2];",
22
+ "var exitWith = process.argv[3];",
23
+ 'if (mode === "write") auth.recordAuthFailure({ write: true });',
24
+ 'if (mode === "read") auth.recordAuthFailure();',
25
+ 'if (exitWith !== "natural") process.exit(Number(exitWith));',
26
+ "",
27
+ ].join("\n");
28
+ describe("installAuthExitCode in a child process (#185)", function () {
29
+ var dir = "";
30
+ var runner = "";
31
+ beforeAll(function () {
32
+ dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-auth-exit-"));
33
+ // authFailure.ts imports nothing, so one transpiled file is the whole module.
34
+ var source = fs_1.default.readFileSync(path_1.default.join(__dirname, "..", "authFailure.ts"), "utf8");
35
+ var compiled = typescript_1.default.transpileModule(source, {
36
+ compilerOptions: {
37
+ module: typescript_1.default.ModuleKind.CommonJS,
38
+ target: typescript_1.default.ScriptTarget.ES2019,
39
+ },
40
+ });
41
+ fs_1.default.writeFileSync(path_1.default.join(dir, "authFailure.js"), compiled.outputText);
42
+ runner = path_1.default.join(dir, "runner.js");
43
+ fs_1.default.writeFileSync(runner, RUNNER);
44
+ });
45
+ afterAll(function () {
46
+ if (dir)
47
+ fs_1.default.rmSync(dir, { recursive: true, force: true });
48
+ });
49
+ function exitStatus(mode, exitWith) {
50
+ var result = (0, child_process_1.spawnSync)(process.execPath, [runner, mode, exitWith], {
51
+ encoding: "utf8",
52
+ timeout: 20000,
53
+ });
54
+ if (result.error)
55
+ throw result.error;
56
+ return result.status;
57
+ }
58
+ it("a rejected write turns process.exit(0) into 77", function () {
59
+ expect(exitStatus("write", "0")).toBe(77);
60
+ });
61
+ it("nothing recorded leaves process.exit(0) at 0", function () {
62
+ expect(exitStatus("none", "0")).toBe(0);
63
+ });
64
+ it("a tolerated 401 read turns process.exit(1) into 77", function () {
65
+ expect(exitStatus("read", "1")).toBe(77);
66
+ });
67
+ it("a tolerated 401 read leaves a clean exit at 0", function () {
68
+ expect(exitStatus("read", "0")).toBe(0);
69
+ });
70
+ it("a rejected write turns process.exit(1) and a natural end into 77", function () {
71
+ expect(exitStatus("write", "1")).toBe(77);
72
+ expect(exitStatus("write", "natural")).toBe(77);
73
+ });
74
+ it("nothing recorded leaves process.exit(1) at 1", function () {
75
+ expect(exitStatus("none", "1")).toBe(1);
76
+ });
77
+ it("any other exit code is left alone, even after a rejected write", function () {
78
+ expect(exitStatus("write", "2")).toBe(2);
79
+ expect(exitStatus("read", "130")).toBe(130);
80
+ });
81
+ });
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const authFailure_1 = require("../authFailure");
4
+ var SECRET = "hunter2-do-not-print";
5
+ var HOST = "example.invalid";
6
+ describe("authFailure (#185)", function () {
7
+ beforeEach(function () {
8
+ (0, authFailure_1.resetAuthFailureState)();
9
+ });
10
+ it("uses a distinct exit code", function () {
11
+ expect(authFailure_1.AUTH_EXIT_CODE).toBe(77);
12
+ expect((0, authFailure_1.isAuthStatus)(401)).toBe(true);
13
+ expect((0, authFailure_1.isAuthStatus)(403)).toBe(true);
14
+ expect((0, authFailure_1.isAuthStatus)(404)).toBe(false);
15
+ expect((0, authFailure_1.isAuthStatus)("401")).toBe(false);
16
+ });
17
+ describe("instanceHost", function () {
18
+ it("reduces an instance value to a bare host", function () {
19
+ expect((0, authFailure_1.instanceHost)(HOST)).toBe(HOST);
20
+ expect((0, authFailure_1.instanceHost)("https://" + HOST + "/")).toBe(HOST);
21
+ expect((0, authFailure_1.instanceHost)("https://" + HOST + "/api/now?x=1")).toBe(HOST);
22
+ });
23
+ it("drops userinfo so a credential in the value cannot leak", function () {
24
+ expect((0, authFailure_1.instanceHost)("https://admin:" + SECRET + "@" + HOST)).toBe(HOST);
25
+ });
26
+ it("returns empty for anything that is not a plain host", function () {
27
+ expect((0, authFailure_1.instanceHost)("")).toBe("");
28
+ expect((0, authFailure_1.instanceHost)(undefined)).toBe("");
29
+ expect((0, authFailure_1.instanceHost)("not a host; echo x")).toBe("");
30
+ });
31
+ });
32
+ describe("classifyAuthRejection", function () {
33
+ it("treats a 401 on any method as a rejection, a write only when it is not a GET", function () {
34
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 401, method: "get" })).toEqual({ status: 401, write: false });
35
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 401, method: "POST" })).toEqual({ status: 401, write: true });
36
+ });
37
+ it("treats a 403 as a rejection only on a write", function () {
38
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 403, method: "GET" })).toBeNull();
39
+ ["post", "PUT", "patch", "DELETE"].forEach(function (method) {
40
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 403, method: method, url: "api/now/table/x" })).toEqual({
41
+ status: 403,
42
+ write: true,
43
+ });
44
+ });
45
+ });
46
+ it("counts the read-only POST endpoints as reads", function () {
47
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 403, method: "POST", url: "api/cadso/dovetail_sync/getManifest/x_s" })).toBeNull();
48
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 403, method: "POST", url: "/api/cadso/dovetail_sync/bulkDownload?x=1" })).toBeNull();
49
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 401, method: "POST", url: "api/cadso/dovetail_sync/bulkDownload" })).toEqual({ status: 401, write: false });
50
+ // A look-alike name is still a write.
51
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 403, method: "POST", url: "api/cadso/dovetail_sync/getManifestX" })).toEqual({ status: 403, write: true });
52
+ });
53
+ it("ignores other statuses and never calls a request with no method a write", function () {
54
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 404, method: "POST" })).toBeNull();
55
+ expect((0, authFailure_1.classifyAuthRejection)({ status: "403", method: "POST" })).toBeNull();
56
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 403, method: undefined })).toBeNull();
57
+ expect((0, authFailure_1.classifyAuthRejection)({ status: 401, method: 7 })).toEqual({ status: 401, write: false });
58
+ });
59
+ it("reports the first rejection of each kind once", function () {
60
+ expect((0, authFailure_1.firstRejectionOfKind)({ status: 403, write: true })).toBe(true);
61
+ expect((0, authFailure_1.firstRejectionOfKind)({ status: 403, write: true })).toBe(false);
62
+ expect((0, authFailure_1.firstRejectionOfKind)({ status: 401, write: true })).toBe(true);
63
+ expect((0, authFailure_1.firstRejectionOfKind)({ status: 401, write: false })).toBe(true);
64
+ });
65
+ });
66
+ describe("requestPath", function () {
67
+ it("keeps only the path", function () {
68
+ expect((0, authFailure_1.requestPath)("api/now/table/x/abc")).toBe("api/now/table/x/abc");
69
+ expect((0, authFailure_1.requestPath)("/api/now/table/x?sysparm_query=a%3Db#frag")).toBe("api/now/table/x");
70
+ expect((0, authFailure_1.requestPath)("https://admin:" + SECRET + "@" + HOST + "/api/now/table/x")).toBe("api/now/table/x");
71
+ });
72
+ it("returns empty for anything it cannot echo safely", function () {
73
+ expect((0, authFailure_1.requestPath)(undefined)).toBe("");
74
+ expect((0, authFailure_1.requestPath)("")).toBe("");
75
+ expect((0, authFailure_1.requestPath)("api/now/table/x y")).toBe("");
76
+ expect((0, authFailure_1.requestPath)("api/$(whoami)")).toBe("");
77
+ });
78
+ });
79
+ describe("reauthCommand", function () {
80
+ it("is plain dove login when no --env was used", function () {
81
+ expect((0, authFailure_1.reauthCommand)()).toBe("dove login");
82
+ });
83
+ it("carries the --env selector the user typed", function () {
84
+ (0, authFailure_1.setAuthContext)({ envPath: "/work/.env.loft", envArg: "loft" });
85
+ expect((0, authFailure_1.reauthCommand)()).toBe("dove login --env loft");
86
+ expect((0, authFailure_1.reauthCommand)("../envs/shop.env")).toBe("dove login --env ../envs/shop.env");
87
+ });
88
+ it("never echoes a selector with shell metacharacters", function () {
89
+ expect((0, authFailure_1.reauthCommand)("loft; echo x")).toBe("dove login --env <name>");
90
+ expect((0, authFailure_1.reauthCommand)("$(whoami)")).toBe("dove login --env <name>");
91
+ expect((0, authFailure_1.reauthCommand)("a b")).toBe("dove login --env <name>");
92
+ });
93
+ });
94
+ describe("buildAuthFailureMessage", function () {
95
+ it("names the host, the env file and the re-auth command for a 401", function () {
96
+ (0, authFailure_1.setAuthContext)({ envPath: "/work/.env.loft", envArg: "loft" });
97
+ var msg = (0, authFailure_1.buildAuthFailureMessage)({
98
+ status: 401,
99
+ action: "pushing sys_script_include > Thing",
100
+ instance: HOST,
101
+ });
102
+ expect(msg).toContain("Unauthorized (401) pushing sys_script_include > Thing");
103
+ expect(msg).toContain(HOST + " rejected the credentials loaded from /work/.env.loft");
104
+ expect(msg).toContain("Re-authenticate with: dove login --env loft");
105
+ expect(msg).toContain("exits 77");
106
+ });
107
+ it("explains a 403 as a refused write and does not offer dove login as the remedy", function () {
108
+ (0, authFailure_1.setAuthContext)({ envPath: "/work/.env", envArg: "" });
109
+ var msg = (0, authFailure_1.buildAuthFailureMessage)({
110
+ status: 403,
111
+ action: "calling POST api/x",
112
+ instance: HOST,
113
+ table: "sys_script_include",
114
+ });
115
+ expect(msg).toContain("Forbidden (403) calling POST api/x");
116
+ expect(msg).toContain(HOST + " accepted the sign-in but refused the write for this user");
117
+ expect(msg).toContain("Check the role or ACL for table sys_script_include for the user in /work/.env");
118
+ expect(msg).toContain("exits 77");
119
+ expect(msg).not.toContain("dove login");
120
+ expect(msg).not.toContain("Re-authenticate");
121
+ });
122
+ it("a 403 with no usable table name says 'the table' and never echoes an odd value", function () {
123
+ var plain = (0, authFailure_1.buildAuthFailureMessage)({ status: 403, action: "calling POST api/x" });
124
+ expect(plain).toContain("Check the role or ACL for the table for the user in the loaded env file");
125
+ var odd = (0, authFailure_1.buildAuthFailureMessage)({
126
+ status: 403,
127
+ action: "calling POST api/x",
128
+ table: "x; echo " + SECRET,
129
+ });
130
+ expect(odd).toContain("for the table for the user");
131
+ expect(odd).not.toContain(SECRET);
132
+ });
133
+ it("a 401 still offers dove login", function () {
134
+ var msg = (0, authFailure_1.buildAuthFailureMessage)({ status: 401, action: "calling GET api/x", instance: HOST });
135
+ expect(msg).toContain("Re-authenticate with: dove login");
136
+ });
137
+ it("falls back to neutral wording when the host and env file are unknown", function () {
138
+ var msg = (0, authFailure_1.buildAuthFailureMessage)({ status: 401, action: "pushing x" });
139
+ expect(msg).toContain("the ServiceNow instance rejected the credentials in the loaded env file");
140
+ expect(msg).toContain("dove login");
141
+ });
142
+ it("never prints a credential, whatever the environment holds", function () {
143
+ var saved = { user: process.env.SN_USER, password: process.env.SN_PASSWORD, key: process.env.SN_API_KEY };
144
+ process.env.SN_USER = "svc-" + SECRET;
145
+ process.env.SN_PASSWORD = SECRET;
146
+ process.env.SN_API_KEY = "key-" + SECRET;
147
+ try {
148
+ (0, authFailure_1.setAuthContext)({ envPath: "/work/.env.loft", envArg: "loft" });
149
+ [401, 403].forEach(function (status) {
150
+ var msg = (0, authFailure_1.buildAuthFailureMessage)({
151
+ status: status,
152
+ action: "pushing x",
153
+ instance: "https://admin:" + SECRET + "@" + HOST,
154
+ });
155
+ expect(msg).not.toContain(SECRET);
156
+ expect(msg).toContain(HOST);
157
+ });
158
+ }
159
+ finally {
160
+ if (saved.user === undefined)
161
+ delete process.env.SN_USER;
162
+ else
163
+ process.env.SN_USER = saved.user;
164
+ if (saved.password === undefined)
165
+ delete process.env.SN_PASSWORD;
166
+ else
167
+ process.env.SN_PASSWORD = saved.password;
168
+ if (saved.key === undefined)
169
+ delete process.env.SN_API_KEY;
170
+ else
171
+ process.env.SN_API_KEY = saved.key;
172
+ }
173
+ });
174
+ });
175
+ describe("resolveExitCode", function () {
176
+ it("leaves every code alone when nothing was rejected", function () {
177
+ expect((0, authFailure_1.resolveExitCode)(0)).toBe(0);
178
+ expect((0, authFailure_1.resolveExitCode)(1)).toBe(1);
179
+ expect((0, authFailure_1.resolveExitCode)(2)).toBe(2);
180
+ expect((0, authFailure_1.resolveExitCode)(undefined)).toBe(0);
181
+ });
182
+ it("re-maps only a generic failure after a rejected read", function () {
183
+ (0, authFailure_1.recordAuthFailure)();
184
+ expect((0, authFailure_1.resolveExitCode)(1)).toBe(77);
185
+ expect((0, authFailure_1.resolveExitCode)(0)).toBe(0);
186
+ expect((0, authFailure_1.resolveExitCode)(2)).toBe(2);
187
+ });
188
+ it("never lets a rejected write exit clean, and keeps other codes", function () {
189
+ (0, authFailure_1.recordAuthFailure)({ write: true });
190
+ expect((0, authFailure_1.resolveExitCode)(0)).toBe(77);
191
+ expect((0, authFailure_1.resolveExitCode)(1)).toBe(77);
192
+ expect((0, authFailure_1.resolveExitCode)(2)).toBe(2);
193
+ expect((0, authFailure_1.resolveExitCode)(130)).toBe(130);
194
+ });
195
+ });
196
+ describe("installAuthExitCode", function () {
197
+ function fakeProcess() {
198
+ var listeners = [];
199
+ var proc = {
200
+ exitCode: undefined,
201
+ on: function (_event, listener) {
202
+ listeners.push(listener);
203
+ return proc;
204
+ },
205
+ emitExit: function (code) {
206
+ listeners.forEach(function (l) {
207
+ l(code);
208
+ });
209
+ },
210
+ };
211
+ return proc;
212
+ }
213
+ it("sets the auth exit code on exit after a rejected write", function () {
214
+ var proc = fakeProcess();
215
+ (0, authFailure_1.installAuthExitCode)(proc);
216
+ (0, authFailure_1.recordAuthFailure)({ write: true });
217
+ proc.emitExit(1);
218
+ expect(proc.exitCode).toBe(77);
219
+ });
220
+ it("does not touch the exit code when nothing was rejected", function () {
221
+ var proc = fakeProcess();
222
+ (0, authFailure_1.installAuthExitCode)(proc);
223
+ proc.emitExit(1);
224
+ expect(proc.exitCode).toBeUndefined();
225
+ });
226
+ });
227
+ });
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ // Tests that `dove`'s init() wires the bare-name walk-up end to end: a
3
+ // `--env <name>` with no file in cwd selects the parent directory's file,
4
+ // loads it, and prints only the chosen path to stderr (never stdout, never
5
+ // anything from the file). Every file here is a fake, created in a temp
6
+ // directory at runtime.
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ // --- Mock setup (must be before imports) ---
45
+ //
46
+ // init() boots the CLI parser, which under Jest would see jest's argv; stub it
47
+ // (same as cred.test.ts). Config loading is stubbed to a pass-through so the
48
+ // test is about the --env override, not dove.config.js discovery.
49
+ jest.mock("../commander", () => ({ initCommands: jest.fn() }));
50
+ jest.mock("../config", () => {
51
+ var actual = jest.requireActual("../config");
52
+ var override;
53
+ return Object.assign({}, actual, {
54
+ setEnvPathOverride: jest.fn(function (p) {
55
+ override = p;
56
+ }),
57
+ loadConfigs: jest.fn(function () {
58
+ return Promise.resolve();
59
+ }),
60
+ getEnvPath: jest.fn(function () {
61
+ if (override === undefined)
62
+ throw new Error("no override");
63
+ return override;
64
+ }),
65
+ });
66
+ });
67
+ // --- Imports (after mocks) ---
68
+ const crypto_1 = __importDefault(require("crypto"));
69
+ const fs_1 = __importDefault(require("fs"));
70
+ const os_1 = __importDefault(require("os"));
71
+ const path_1 = __importDefault(require("path"));
72
+ const bootstrap_1 = require("../bootstrap");
73
+ const ConfigManager = __importStar(require("../config"));
74
+ var ENV_PREFIX = ".env.";
75
+ var FAKE_CONTENT = "SN_INSTANCE=fakebootwalkup\nSN_USER=fakeuser\nSN_PASSWORD=fakepass-not-real\n";
76
+ describe("init() — --env bare name found in a parent directory", function () {
77
+ var root;
78
+ var savedCwd;
79
+ var savedArgv;
80
+ var savedKeys = ["SN_INSTANCE", "SN_USER", "SN_PASSWORD"];
81
+ var savedEnv = {};
82
+ beforeEach(function () {
83
+ root = fs_1.default.realpathSync(fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-boot-walkup-")));
84
+ savedCwd = process.cwd();
85
+ savedArgv = process.argv;
86
+ savedKeys.forEach(function (k) {
87
+ savedEnv[k] = process.env[k];
88
+ delete process.env[k];
89
+ });
90
+ });
91
+ afterEach(function () {
92
+ process.chdir(savedCwd);
93
+ process.argv = savedArgv;
94
+ savedKeys.forEach(function (k) {
95
+ if (savedEnv[k] === undefined)
96
+ delete process.env[k];
97
+ else
98
+ process.env[k] = savedEnv[k];
99
+ });
100
+ fs_1.default.rmSync(root, { recursive: true, force: true });
101
+ });
102
+ it("selects and loads the parent file and logs only its path to stderr", async function () {
103
+ // A random name, so the walk above the temp root can never hit a stray file.
104
+ var name = "bootwalkup" + crypto_1.default.randomBytes(6).toString("hex");
105
+ var nested = path_1.default.join(root, "wt", "pkg");
106
+ fs_1.default.mkdirSync(nested, { recursive: true });
107
+ var target = path_1.default.join(root, ENV_PREFIX + name);
108
+ fs_1.default.writeFileSync(target, FAKE_CONTENT);
109
+ process.chdir(nested);
110
+ process.argv = ["node", "dove", "status", "--env", name];
111
+ var errOut = [];
112
+ var stdOut = [];
113
+ var errSpy = jest
114
+ .spyOn(process.stderr, "write")
115
+ .mockImplementation(function (chunk) {
116
+ errOut.push(String(chunk));
117
+ return true;
118
+ });
119
+ var outSpy = jest
120
+ .spyOn(process.stdout, "write")
121
+ .mockImplementation(function (chunk) {
122
+ stdOut.push(String(chunk));
123
+ return true;
124
+ });
125
+ try {
126
+ await (0, bootstrap_1.init)();
127
+ }
128
+ finally {
129
+ errSpy.mockRestore();
130
+ outSpy.mockRestore();
131
+ }
132
+ expect(ConfigManager.setEnvPathOverride).toHaveBeenCalledWith(target);
133
+ expect(process.env.SN_INSTANCE).toBe("fakebootwalkup");
134
+ var err = errOut.join("");
135
+ expect(err).toContain("dove: --env " + name + ": using " + target);
136
+ expect(err).toContain("found in a parent directory");
137
+ expect(err).not.toContain("fakepass-not-real");
138
+ expect(stdOut.join("")).not.toContain(target);
139
+ });
140
+ it("prints nothing when the file is in cwd", async function () {
141
+ var name = "bootwalkup" + crypto_1.default.randomBytes(6).toString("hex");
142
+ var target = path_1.default.join(root, ENV_PREFIX + name);
143
+ fs_1.default.writeFileSync(target, FAKE_CONTENT);
144
+ process.chdir(root);
145
+ process.argv = ["node", "dove", "status", "--env", name];
146
+ var errOut = [];
147
+ var errSpy = jest
148
+ .spyOn(process.stderr, "write")
149
+ .mockImplementation(function (chunk) {
150
+ errOut.push(String(chunk));
151
+ return true;
152
+ });
153
+ try {
154
+ await (0, bootstrap_1.init)();
155
+ }
156
+ finally {
157
+ errSpy.mockRestore();
158
+ }
159
+ expect(ConfigManager.setEnvPathOverride).toHaveBeenLastCalledWith(target);
160
+ expect(errOut.join("")).not.toContain("found in a parent directory");
161
+ });
162
+ });
@@ -7,6 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ const crypto_1 = __importDefault(require("crypto"));
10
11
  const fs_1 = __importDefault(require("fs"));
11
12
  const os_1 = __importDefault(require("os"));
12
13
  const path_1 = __importDefault(require("path"));
@@ -116,7 +117,18 @@ describe("resolveEnvArgPath", function () {
116
117
  expect((0, envArg_1.resolveEnvArgPath)(raw, tmpDir)).toBe(path_1.default.join(tmpDir, ENV_PREFIX + "demo8"));
117
118
  });
118
119
  it("defaults to process.cwd() when no cwd is given", function () {
119
- expect((0, envArg_1.resolveEnvArgPath)("demo8")).toBe(path_1.default.resolve(process.cwd(), ENV_PREFIX + "demo8"));
120
+ // Hermetic: run from a temp dir with a random name, so a bare name can't
121
+ // walk up to a real per-instance file above the checkout.
122
+ var savedCwd = process.cwd();
123
+ var name = "cwddefault" + crypto_1.default.randomBytes(6).toString("hex");
124
+ var dir = fs_1.default.realpathSync(tmpDir);
125
+ process.chdir(dir);
126
+ try {
127
+ expect((0, envArg_1.resolveEnvArgPath)(name)).toBe(path_1.default.join(dir, ENV_PREFIX + name));
128
+ }
129
+ finally {
130
+ process.chdir(savedCwd);
131
+ }
120
132
  });
121
133
  it("throws on an empty or non-string selector", function () {
122
134
  expect(function () {