mitre / saf_action

GitHub Action for SAF CLI
https://github.com/marketplace/actions/saf-cli-action
Other
6 stars 0 forks source link

Tests failing false positive #64

Open Amndeep7 opened 2 months ago

Amndeep7 commented 2 months ago

https://github.com/mitre/saf_action/actions/runs/10185845654/job/28176277275

Output:

> saf_action@1.7.2 test
> jest

  ●  process.exit called with "1"

       [6](https://github.com/mitre/saf_action/actions/runs/10185845654/job/28176277275#step:3:7) |     let inputFilePath = path.resolve('./test/sample_data/red_hat_good.json');
       [7](https://github.com/mitre/saf_action/actions/runs/10185845654/job/28176277275#step:3:8) |     process.env['INPUT_COMMAND_STRING'] = `view summary -i ${inputFilePath}`;
    >  [8](https://github.com/mitre/saf_action/actions/runs/10185845654/job/28176277275#step:3:9) |     await saf_action({safCLIPath: "./node_modules/@mitre/saf/lib/index.js"});
         |     ^
       [9](https://github.com/mitre/saf_action/actions/runs/10185845654/job/28176277275#step:3:10) |     delete process.env['INPUT_COMMAND_STRING'];
      [10](https://github.com/mitre/saf_action/actions/runs/10185845654/job/28176277275#step:3:11) |   });
      11 |   it('should run SAF with a colon topic separator in the command string', async () => {

      at Summary.run (node_modules/@mitre/saf/src/commands/view/summary.ts:151:15)

With additional debugging:

amann saf_action ❯❯❯ npm run test

> saf_action@1.7.2 test
> jest

  console.log
    entered test

      at Object.log (test/index.test.js:6:13)

  console.log
    path: /Users/amann/work/saf/saf_action/test/sample_data/red_hat_good.json

      at Object.log (test/index.test.js:8:13)

  console.log
    TypeError: Cannot read properties of undefined (reading 'flatten')

      at Summary.run (node_modules/@mitre/saf/src/commands/view/summary.ts:145:7)

  ●  process.exit called with "1"

I recently made changes to how we import the flat package in the SAF CLI to do a dynamic import. This didn't cause any problems when running the SAF CLI by hand, nor does it cause problems when the action is used in a live setting (both in the examples workflow here as well as in a branch I made on the rhel8 inspec repo). I feel like it's just yet another weirdness with how the testing framework interacts with things that in this case is not playing well with the async (and not really awaited) nature of how we are currently dynamically importing things.

Long term solution is to move everything to ESM. In the meantime, this will fail.