Skip to content

Conversation

@Ma11hewThomas
Copy link
Contributor

No description provided.

…d add-insights

- Create flaky.test.ts with 6 new tests (100% coverage)
- Add type filtering tests to filter.test.ts (improve to 91.66% statements, 100% functions)
- Add file not found and invalid JSON tests to validate.test.ts (improve branch coverage)
- Add edge case tests to add-insights.test.ts for error handling

Total tests increased from 57 to 70 (13 new tests)
Overall statement coverage improved from 51.99% to 61.73%
Function coverage improved from 69.23% to 84.61%
Comment on lines +76 to +100
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.19.0"
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Type check
run: npx tsc --noEmit

- name: Run linter
run: npm run lint:check

- name: Check formatting
run: npm run format:check

security:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 1 day ago

To fix this, explicitly define a permissions block so that the GITHUB_TOKEN used by jobs has only the minimal required scopes. The lint and security jobs only read the code and run local commands, so contents: read is sufficient. The test job uses ctrf-io/github-test-reporter@v1 with github-report: true and similar options; such reporting actions typically need to read PRs and statuses and may need to write a PR comment or summary. A conservative and still least-privilege choice is to give that job contents: read and pull-requests: write (enough to post PR comments) while keeping other scopes absent.

The single best way with minimal functional change is:

  • Add a top-level permissions: contents: read so that all jobs default to read-only repository access.
  • Override for the test job with a job-level permissions block that grants contents: read and pull-requests: write. This keeps lint and security as read-only, and gives test exactly what it likely needs for GitHub reporting.

All changes are confined to .github/workflows/main.yaml by inserting the new permissions blocks without altering any existing steps.

Suggested changeset 1
.github/workflows/main.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -4,8 +4,14 @@
   push:
   pull_request:
 
+permissions:
+  contents: read
+
 jobs:
   test:
+    permissions:
+      contents: read
+      pull-requests: write
     runs-on: ubuntu-latest
 
     strategy:
EOF
@@ -4,8 +4,14 @@
push:
pull_request:

permissions:
contents: read

jobs:
test:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest

strategy:
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +101 to +121
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Build
run: npx tsc
- name: Merge
run: npx ctrf-cli merge test-reports
- name: Flaky
run: npx ctrf-cli flaky test-reports/ctrf-report-one.json
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.19.0"
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Run security audit
run: npm audit --audit-level=moderate

- name: Check for known vulnerabilities
run: npx audit-ci --moderate

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 1 day ago

In general, the fix is to explicitly declare a permissions block for the workflow or each job so that the GITHUB_TOKEN has only the minimal capabilities required. Since all jobs in this workflow only need to read repository contents and use Actions, we can safely set permissions: contents: read at the workflow root, which will apply to all jobs. If at some point a job needs additional scopes (for example, checks: write or pull-requests: write), it can override or extend permissions at the job level.

The best minimal change here is to add a workflow‑level permissions block directly under the name: Build and Test line in .github/workflows/main.yaml. Based on the current steps, contents: read is sufficient: all interactions with GitHub (checkout, reading code, reading existing artifacts) only require read access; the third‑party reporter action typically only needs to post check results or summaries via the provided token, which many implementations can do with contents: read plus the default checks/reporting behavior granted by GitHub when contents: read is set (if a future failure indicates it needs e.g. checks: write, that can be added then). No additional imports or methods are required, just the YAML change.

Concretely:

  • Edit .github/workflows/main.yaml.
  • Insert a permissions: block after line 1 (name: Build and Test) with contents: read.
  • Leave the rest of the workflow unchanged.
Suggested changeset 1
.github/workflows/main.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -1,4 +1,6 @@
 name: Build and Test
+permissions:
+  contents: read
 
 on:
   push:
EOF
@@ -1,4 +1,6 @@
name: Build and Test
permissions:
contents: read

on:
push:
Copilot is powered by AI and may make mistakes. Always verify output.
import fs from 'fs'
import path from 'path'
import os from 'os'
import { ReportBuilder, TestBuilder, addInsights, stringify, parse } from 'ctrf'
Comment on lines +5 to +12
import {
ReportBuilder,
TestBuilder,
filterTests,
isCTRFReport,
stringify,
parse,
} from 'ctrf'
Comment on lines +5 to +11
import {
ReportBuilder,
TestBuilder,
generateReportId,
stringify,
parse,
} from 'ctrf'
Comment on lines +5 to +11
import {
ReportBuilder,
TestBuilder,
generateTestId,
stringify,
parse,
} from 'ctrf'
Comment on lines +5 to +12
import {
ReportBuilder,
TestBuilder,
validate,
isCTRFReport,
stringify,
parse,
} from 'ctrf'
@Ma11hewThomas Ma11hewThomas merged commit 6ea278e into main Jan 25, 2026
16 checks passed
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