]> git.ardis.lu - envpass/commitdiff
Add log and test for `outFile` and `injectInProcess` intersection
authorArdis Lu <ardisglu@gmail.com>
Sat, 19 Sep 2026 05:29:56 +0000 (22:29 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 19 Sep 2026 05:29:56 +0000 (22:29 -0700)
src/command.js
test/index.test.js

index 3b571078f1799b3bfd3836042d93b78a1e500042..2119874279b1d3454fcbcdbc08727cbf48c8c40e 100644 (file)
@@ -166,6 +166,9 @@ export async function decrypt(options = {}, { args = [] } = {}) {
   logger.debug?.('All environment variables handled.');
 
   if (injectInProcess) {
+    if (outFile && outFile !== inFile) {
+      logger.debug?.('Both injectInProcess and outFile arguments were provided, ignoring outFile.');
+    }
     for (const [envVar, value] of Object.entries(decryptedEnv)) {
       process.env[envVar] = value;
     }
index c5e65c762d372fc79617fe63dcad829f1244531e..62ce9481e0f15c16953faad8fddeef104eda9e19 100644 (file)
@@ -1,5 +1,6 @@
 import { suite, test } from 'node:test';
-import { deepStrictEqual, rejects } from 'node:assert';
+import { deepStrictEqual, rejects, ok } from 'node:assert';
+import { existsSync } from 'node:fs';
 
 import { encrypt, decrypt } from '#src/index.js';
 import { WINDOW_EXPIRATION_DURATION } from '#src/getPrf.js';
@@ -163,6 +164,30 @@ suite('decrypt', { concurrency: true }, () => {
     delete process.env.INJECTION_TEST;
     logger.assertCounts({ debug: 3, info: 0, warn: 0, error: 0 });
   });
+  test('ignores outFile when injectInProcess is set', async (t) => {
+    const envFile = await setupEnv(t, INJECTED_ENV);
+    const outFile =  `${envFile}_TEST_OUT.tmp`;
+
+    ok(!existsSync(outFile));
+    deepStrictEqual(process.env.INJECTION_TEST, undefined);
+    await decrypt({ inFile: envFile, injectInProcess: true, outFile });
+    ok(!existsSync(outFile));
+    deepStrictEqual(process.env.INJECTION_TEST, 'INJECTED');
+    delete process.env.INJECTION_TEST;
+  });
+  test('ignores outFile when injectInProcess is set (with logs)', async (t) => {
+    const envFile = await setupEnv(t, INJECTED_ENV);
+    const outFile =  `${envFile}_TEST_OUT.tmp`;
+    const logger = new MockLogger();
+
+    ok(!existsSync(outFile));
+    deepStrictEqual(process.env.INJECTION_TEST, undefined);
+    await decrypt({ inFile: envFile, injectInProcess: true, outFile, logger });
+    ok(!existsSync(outFile));
+    deepStrictEqual(process.env.INJECTION_TEST, 'INJECTED');
+    delete process.env.INJECTION_TEST;
+    logger.assertCounts({ debug: 4, info: 0, warn: 0, error: 0 });
+  });
   test('passes through excess args to execute', async (t) => {
     const envFile = await setupEnv(t, STD_ENV);
     /** @type {(command: string) => void} */
This page took 0.043404 seconds and 4 git commands to generate.