Skip to content

fix(calendar): allow configuring the raw repository base - #32

Merged
pentaoa merged 2 commits into
wormforce:mainfrom
FortuneCatOfSummer:fix/calendar-configurable-raw-base
Oct 30, 2026
Merged

pentaoa merged 2 commits into
wormforce:mainfrom
FortuneCatOfSummer:fix/calendar-configurable-raw-base

Conversation

@FortuneCatOfSummer

@FortuneCatOfSummer FortuneCatOfSummer commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Extract the HTTPS base resolution shared with the online layer into
    src/core/raw-base.ts
  • Add SUSTECH_CALENDAR_RAW_BASE for the academic calendar, defaulting to
    https://raw.githubusercontent.com/dumixthestpd/sustech-calendar/main
  • Reject non-HTTPS values, values with embedded credentials, and values with a
    query string or fragment, with CALENDAR_RAW_BASE_INVALID
  • Make the merged online default-base test hermetic when
    SUSTECH_ONLINE_RAW_BASE is set in the caller's environment
  • Document both variables in the README

Follow-up to #30, refs #29.

Why

src/calendar/client.ts still hard-coded the same raw GitHub base, so
calendar day and tis schedule kept failing on restricted networks even
after the online layer became configurable.

Behaviour

  • No environment variable: identical to today.
  • SUSTECH_CALENDAR_RAW_BASE=https://ghfast.top/https://raw.githubusercontent.com/dumixthestpd/sustech-calendar/main:
    calendar reads go through the mirror.
  • Invalid value: fails with CALENDAR_RAW_BASE_INVALID instead of silently
    reading another source.

Security

The shared resolver rejects URLs with embedded credentials for both
SUSTECH_CALENDAR_RAW_BASE and SUSTECH_ONLINE_RAW_BASE, so a mirror URL
cannot carry a token into request headers or error output. The online layer
also keeps its exact URL allowlist and redirect: "error" behaviour.

Tests

  • npm run check
  • npm test — new src/test/calendar-raw-base.test.ts covers the default, a
    mirror override, trailing-slash/whitespace trimming, invalid values including
    userinfo, and that loadYear requests the configured base. 504 tests: 487
    pass, 12 skip; the 5 failures are the pre-existing Windows symlink tests
    (EPERM without Developer Mode).

The calendar client still hard-codes raw.githubusercontent.com, so
`calendar day` and `tis schedule` fail on networks where that host is
unreachable even after the online layer became configurable.

Extract the HTTPS base resolution shared with the online layer and add
SUSTECH_CALENDAR_RAW_BASE, defaulting to the public calendar repository.
Values must be plain HTTPS URLs without a query or fragment; invalid
values fail with CALENDAR_RAW_BASE_INVALID.

Also make the online default-base test hermetic when
SUSTECH_ONLINE_RAW_BASE is set in the caller's environment, and document
both variables in the README.

Refs wormforce#29, wormforce#30.
A base URL such as https://user:token@mirror.example/repo would send the
embedded secret to the mirror. Reject any URL with userinfo so
SUSTECH_CALENDAR_RAW_BASE and SUSTECH_ONLINE_RAW_BASE cannot smuggle
credentials into requests.

Cover both resolvers with tests and update the README and online docs.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@pentaoa
pentaoa merged commit fe44a19 into wormforce:main Oct 30, 2026
6 checks passed

pentaoa commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks @FortuneCatOfSummer — exactly the calendar follow-up we wanted after #30. Shared raw-base resolver, credential rejection, and the hermetic online test are all appreciated. Merged.

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.

3 participants