Skip to content

fix: fall back to GitHub API for commit author when Firebase token la…#2777

Open
lbondaryk wants to merge 4 commits intomasterfrom
CLUE-427-authors-cannot-commit-clue-changes
Open

fix: fall back to GitHub API for commit author when Firebase token la…#2777
lbondaryk wants to merge 4 commits intomasterfrom
CLUE-427-authors-cannot-commit-clue-changes

Conversation

@lbondaryk
Copy link
Contributor

…cks name/email (CLUE-427)

Extract resolveCommitAuthor helper that tries the Firebase decoded token first, then falls back to the GitHub API for missing name or email. This fixes the 'Could not determine author information from token' error for users whose GitHub profiles lack a public name or email. Add unit tests covering all fallback branches.

…cks name/email (CLUE-427)

Extract resolveCommitAuthor helper that tries the Firebase decoded token
first, then falls back to the GitHub API for missing name or email.
This fixes the 'Could not determine author information from token' error
for users whose GitHub profiles lack a public name or email. Add unit
tests covering all fallback branches.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses missing commit author metadata when pushing units by introducing a helper that derives author name/email from the Firebase decoded token, falling back to the authenticated GitHub user profile when needed (CLUE-427).

Changes:

  • Add resolveCommitAuthor() helper to derive commit author from token, with GitHub API fallback.
  • Update pushUnit route to use the new helper and a clearer error message on failure.
  • Add Jest unit tests covering the fallback branches; add Jest-related dev dependencies.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
authoring-api/src/routes/push-unit.ts Switches commit author resolution to resolveCommitAuthor() with improved error messaging.
authoring-api/src/helpers/resolve-commit-author.ts New helper implementing token-first, GitHub API fallback logic for commit author.
authoring-api/src/helpers/resolve-commit-author.test.ts New Jest tests covering token-only, partial token, GitHub fallbacks, and error path.
authoring-api/package.json Adds Jest/ts-jest and Jest types to support the new unit tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 24 to 35
"@types/cors": "^2.8.19",
"@types/jest": "^30.0.0",
"@typescript-eslint/eslint-plugin": "^8.39.1",
"@typescript-eslint/parser": "^8.39.1",
"dotenv": "16.4.5",
"eslint": "^8.57.1",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.32.0",
"firebase-tools": "^13.15.1",
"jest": "^30.2.0",
"ts-jest": "^29.4.6",
"typescript": "^5.9.2"
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

jest/ts-jest are added but there is no test script in this package’s scripts. As a result, npm test (and any CI expecting it) won’t run the new unit tests; add a test (and optionally test:watch/test:coverage) script wired to jest.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +5
import {resolveCommitAuthor} from "./resolve-commit-author";

// Minimal mock matching the Octokit shape used by resolveCommitAuthor
function mockOctokit(userData: {name?: string | null; email?: string | null; login: string}) {
return {
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

This test file lives under src/, and authoring-api/tsconfig.json includes src in the build, so it will be compiled into lib/ and shipped with the deployed function bundle. Consider moving tests under a dedicated test/ directory (as other packages in this repo do) and/or excluding **/*.test.ts from the production tsc build to avoid deploying test artifacts.

Copilot uses AI. Check for mistakes.
@cypress
Copy link

cypress bot commented Feb 18, 2026

collaborative-learning    Run #17889

Run Properties:  status check passed Passed #17889  •  git commit 7d735b368d: chore: address PR review - fix test types, add CI integration, exclude from root...
Project collaborative-learning
Branch Review CLUE-427-authors-cannot-commit-clue-changes
Run status status check passed Passed #17889
Run duration 03m 04s
Commit git commit 7d735b368d: chore: address PR review - fix test types, add CI integration, exclude from root...
Committer lbondaryk
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
View all changes introduced in this branch ↗︎

…LUE-427)

Add npm test script wired to jest so tests run via npm test and CI.
Exclude *.test.ts from tsconfig build to prevent test artifacts from
being compiled into lib/ and deployed with the function bundle.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lbondaryk lbondaryk assigned emcelroy and unassigned emcelroy Feb 18, 2026
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.45%. Comparing base (d56cbcd) to head (7d735b3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2777      +/-   ##
==========================================
- Coverage   86.23%   85.45%   -0.78%     
==========================================
  Files         846      846              
  Lines       46028    46028              
  Branches    11919    11919              
==========================================
- Hits        39691    39332     -359     
- Misses       5939     6275     +336     
- Partials      398      421      +23     
Flag Coverage Δ
cypress ?
cypress-regression 75.13% <ø> (-1.18%) ⬇️
cypress-smoke 43.42% <ø> (ø)
jest 50.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@emcelroy emcelroy left a comment

Choose a reason for hiding this comment

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

Generally looking good, but some changes are needed.

I left a couple suggestions in resolve-commit-author.test.ts that should be applied.

Also, to get the new tests in /authoring-api to work correctly in CI (they're failing right now), you'll need to do the following...

  • in the root directory package.json file, add "/authoring-api/" to the testPathIgnorePatterns array.

  • in .github/workflows/ci.yml, after cms/package-lock.json on line 54, add authoring-api/package-lock.json. Then after this part a few lines down from there:

      - name: Install CMS Dependencies
        working-directory: ./cms
        run: npm ci

add this:

      - name: Install Authoring API Dependencies
        working-directory: ./authoring-api
        run: npm ci
      - name: Run Authoring API Tests
        working-directory: ./authoring-api
        run: npm test

Comment on lines 11 to 12
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally if you can avoid casting to any, it's best not to. It would be pretty simple and better to cast to Octokit like so:

Suggested change
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
} as unknown as Octokit;

You'll also have to add import {Octokit} from "@octokit/rest"; at the top of the file for that to work.

Casting to any makes it so any type errors that might occur later in the test won't be caught.

Comment on lines 22 to 23
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same suggestion as lines 11-12 above.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as unknown as Octokit;

Comment on lines +34 to +35
"jest": "^30.2.0",
"ts-jest": "^29.4.6",
Copy link
Contributor

@emcelroy emcelroy Feb 19, 2026

Choose a reason for hiding this comment

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

Just a note that I've only seen jest and ts-jest with matching version numbers in our projects (as in the package,json in the root directory where both are v28). I thought the versions always went together, but apparently ts-jest v29 will work with jest v30 according to https://github.com/kulshekhar/ts-jest/blob/main/package.json where it lists "@jest/types": "^29.0.0 || ^30.0.0" and "jest": "^29.0.0 || ^30.0.0" under peerDependencies. (And there is no v30 of ts-jest yet.)

…e from root jest (CLUE-427)

Replace `as any` with `as unknown as Octokit` in test mocks for type
safety. Add authoring-api install and test steps to CI workflow. Add
/authoring-api/ to root testPathIgnorePatterns to prevent root jest
from picking up authoring-api tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lbondaryk
Copy link
Contributor Author

@emcelroy I think I've addressed your comments here? Can you approve?

@emcelroy emcelroy self-requested a review February 19, 2026 18:06
Copy link
Contributor

@emcelroy emcelroy left a comment

Choose a reason for hiding this comment

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

Looks good 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments