Skip to content

ci: add test workflow step to output logs - #10347

Draft
dlarocque wants to merge 5 commits into
mainfrom
dl/test-ci-logs
Draft

dlarocque wants to merge 5 commits into
mainfrom
dl/test-ci-logs

Conversation

@dlarocque

Copy link
Copy Markdown
Contributor

No description provided.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b286522

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the CI test logging mechanism by introducing structured JSON manifests for test suites and writing logs directly to files under a .ci-logs directory. While these changes improve log management, two key issues were identified in the review: first, using synchronous file operations inside asynchronous stream handlers in run_tests_in_ci.js blocks the event loop and can cause crashes due to race conditions; second, an O(N^2) lookup complexity in print_test_logs.js should be optimized to O(N) using a Set to track already recorded log files.

Comment thread scripts/run_tests_in_ci.js Outdated
Comment thread scripts/print_test_logs.js Outdated
@dlarocque

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the CI test logging mechanism to stream test output directly to log files and write JSON manifests for each test run, updating the log printing script to parse these manifests. Feedback on these changes includes a request to remove a deliberate crash test added to logger.test.ts for CI verification before merging, and a recommendation to wrap the process spawning and stream piping in run_tests_in_ci.js within a try-catch block to handle potential synchronous failures or undefined streams robustly.

Comment on lines +110 to +117
it('deliberate crash for CI verification', () => {
console.log('MARKER: executing deliberate crash in logger.test.ts');
if (typeof process !== 'undefined' && process.kill) {
process.kill(process.pid, 'SIGKILL');
} else {
throw new Error('DELIBERATE_CI_TEST_CRASH');
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test deliberately crashes the process or throws an error to verify the CI logging workflow. While useful for testing the CI pipeline changes, keeping this in the codebase will cause the test suite to fail consistently for everyone. Please remove this test before merging.

Comment on lines +84 to 114
const testProcess = spawn('yarn', ['--cwd', dir, scriptName]);

testProcess.childProcess.stdout.pipe(logStream, { end: false });
testProcess.childProcess.stderr.pipe(logStream, { end: false });

async function recordManifest(status, exitCode) {
try {
await new Promise(resolve => logStream.end(resolve));
} catch (e) {}
try {
const manifestPath = path.join(
manifestsDir,
`${safeName}-${safeScript}.json`
);
fs.writeFileSync(
manifestPath,
JSON.stringify({
packageName: name,
scriptName,
status,
exitCode,
logFile
})
);
} catch (e) {}
}

try {
await testProcess;
await recordManifest('Success', 0);
console.log('Success: ' + name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If spawn fails synchronously, or if testProcess.childProcess or its stdout/stderr streams are undefined/null, the script will throw an unhandled exception outside of the try/catch block. This will crash the script abruptly without writing a failure manifest.

To make this robust, we should define recordManifest first, and then wrap both the spawn call and the stream piping inside the try/catch block, along with defensive checks for the child process streams.

  async function recordManifest(status, exitCode) {
    try {
      await new Promise(resolve => logStream.end(resolve));
    } catch (e) {}
    try {
      const manifestPath = path.join(
        manifestsDir,
        `${safeName}-${safeScript}.json`
      );
      fs.writeFileSync(
        manifestPath,
        JSON.stringify({
          packageName: name,
          scriptName,
          status,
          exitCode,
          logFile
        })
      );
    } catch (e) {}
  }

  try {
    const testProcess = spawn('yarn', ['--cwd', dir, scriptName]);

    if (testProcess.childProcess) {
      if (testProcess.childProcess.stdout) {
        testProcess.childProcess.stdout.pipe(logStream, { end: false });
      }
      if (testProcess.childProcess.stderr) {
        testProcess.childProcess.stderr.pipe(logStream, { end: false });
      }
    }

    await testProcess;
    await recordManifest('Success', 0);
    console.log('Success: ' + name);

@MarkDuckworth MarkDuckworth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is effective. I'm in support of making the chage.

const testProcess = spawn('yarn', ['--cwd', dir, scriptName]);

testProcess.childProcess.stdout.pipe(logStream, { end: false });
testProcess.childProcess.stderr.pipe(logStream, { end: false });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate lines expected?

env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
- name: Print Test Failure Logs
if: always()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there value in printing the logs if the previous step failed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants