Skip to content

Split PMC mutation surface and stabilize Compose ports - #1176

Merged
Asherlc merged 12 commits into
mainfrom
Asherlc/split-slow-stryker-files
May 25, 2026
Merged

Asherlc merged 12 commits into
mainfrom
Asherlc/split-slow-stryker-files

Conversation

@Asherlc

@Asherlc Asherlc commented May 24, 2026 •

Copy link
Copy Markdown
Owner

Split PMC chart computation out of PmcRepository into focused calculator classes with 1:1 colocated tests, reducing the slow Stryker shard surface.
Add a stable auto-port Compose flow (pnpm compose:up) that writes .env.local and starts DB/ClickHouse/Redis through that env file so local services avoid collisions without changing ports after restarts.
Record the source/test 1:1 guideline in AGENTS.md and update README/.env.example for local setup.
Validation: pnpm lint, root/server/web tsc --noEmit, focused PMC vitest, earlier targeted PMC Stryker 100% in 7m45s; full test:changed and a later Stryker dry run were blocked locally by unrelated ClickHouse/MSW integration instability.

Summary by CodeRabbit

  • New Features

    • Simplified local development setup with streamlined command (pnpm compose:up) replacing manual Docker commands.
    • Dynamic port binding for local services (Postgres, ClickHouse, Redis) eliminating hardcoded configuration.
  • Documentation

    • Updated Quick Start and Development guides to reflect new setup workflow.
    • Updated configuration example to use service discovery patterns.
  • Tests

    • Added comprehensive test coverage for performance calculation modules.

Review Change Stack

Copilot AI review requested due to automatic review settings May 24, 2026 18:54
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sourcery-ai sourcery-ai 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.

Sorry @Asherlc, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented May 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Asherlc, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 4 minutes and 21 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 35547eb8-ddff-4166-9f0c-9b4fa5f0faa4

📥 Commits

Reviewing files that changed from the base of the PR and between e85216b and 46541d0.

📒 Files selected for processing (10)
  • STANDARDS.md
  • packages/server/src/repositories/pmc-chart-calculator.test.ts
  • packages/server/src/repositories/pmc-chart-calculator.ts
  • packages/server/src/repositories/pmc-ewma-calculator.test.ts
  • packages/server/src/repositories/pmc-ewma-calculator.ts
  • packages/server/src/repositories/pmc-repository.ts
  • packages/server/src/repositories/pmc-training-load-calculator.test.ts
  • packages/server/src/repositories/pmc-training-load-calculator.ts
  • scripts/compose-env.test.ts
  • scripts/compose-env.ts
📝 Walkthrough

Walkthrough

The PR automats local development by replacing fixed Docker Compose port bindings with dynamic allocation via ${*_PORT:-0} variables, introduces a compose-env.ts script to resolve and write those ports to .env.local at startup, refactors PMC chart computation out of PmcRepository into specialized PmcChartCalculator, PmcTrainingLoadCalculator, and PmcEwmaCalculator classes, and updates developer documentation to invoke the new workflow.

Changes

Local Infrastructure & Development Workflow

Layer / File(s) Summary
Dynamic Docker Compose port configuration
docker-compose.yml, .env.example
Docker Compose services for db, clickhouse, and redis bind to dynamic host ports using ${*_PORT:-0} on 127.0.0.1. .env.example removes hardcoded CLICKHOUSE_URL and DATABASE_URL values, documenting the Docker Compose–generated port approach with placeholders for *_PORT and derived URLs.
Environment generation script and npm integration
scripts/compose-env.ts, package.json
New compose-env.ts script resolves service ports via docker compose port, falls back to existing env values, allocates unused local TCP ports, constructs dotenv payloads with DATABASE_URL, CLICKHOUSE_URL, and REDIS_URL, and writes to .env.local when invoked with --write. New npm scripts compose:env and compose:up orchestrate script execution and container startup.
Developer workflow and testing guidelines
README.md, AGENTS.md
README Quick Start and Development sections replace manual docker compose up -d db clickhouse redis with pnpm compose:up, and add --env-file .env.local to PeerDB Docker Compose invocations. AGENTS.md adds a testing guideline requiring 1:1 mapping between test and source files.

PMC Chart Calculation Refactoring

Layer / File(s) Summary
Training load calculation foundation
packages/server/src/repositories/pmc-training-load-calculator.ts, packages/server/src/repositories/pmc-training-load-calculator.test.ts
New PmcTrainingLoadCalculator defines PmcActivityRow, PmcNormalizedPowerRow, and PmcTrainingStressModel interfaces. buildTrainingStressModel pairs TRIMP and power-TSS values when threshold power and normalized power are available; calculateDailyLoad computes per-activity training stress using priority order (power-based → regression model → heart-rate-based) and aggregates by date. Tests validate power/HR selection, daily aggregation, and model input filtering rules.
EWMA calculation for performance tracking
packages/server/src/repositories/pmc-ewma-calculator.ts, packages/server/src/repositories/pmc-ewma-calculator.test.ts
New PmcEwmaCalculator computes chronic and acute exponentially weighted moving averages from daily load values, derives training stress balance (CTL − ATL), applies warmup filtering, and returns trimmed PmcDataPoint[] from first point where CTL ≥ 0.1. Tests verify acute/chronic response ordering, zero-load behavior, and consecutive date generation with decay on rest days.
Chart orchestration and repository delegation
packages/server/src/repositories/pmc-chart-calculator.ts, packages/server/src/repositories/pmc-chart-calculator.test.ts, packages/server/src/repositories/pmc-repository.ts
New PmcChartCalculator wires PmcTrainingLoadCalculator and PmcEwmaCalculator, orchestrates training-load and EWMA computation, derives global/resting heart rates, estimates FTP from regression, and returns PmcChartResult with learned or generic model. PmcRepository.getChart refactored to instantiate and delegate to PmcChartCalculator, removing prior in-repository regression modeling, daily load aggregation, EWMA computation, and private helper methods. Tests cover missing global max HR, FTP derivation, model metadata rounding, and resting HR impact on load.
Repository test refactoring
packages/server/src/repositories/pmc-repository.test.ts
Simplified test fixtures to use dynamic dateStringDaysAgo() helper instead of fixed dates. Consolidated repository factory into makeRepoHarness returning { repo, execute, query }. Refactored sensor store mock to route rolling_30s_power queries to normalized-power rows. Replaced behavioral/mutation-focused tests with query parameterization and result-shape assertions: verifying timezone, expanded query window, queryDays: 442 computation, and that returned chart contains exactly { data, model } keys. Removed direct TrainingStressCalculator import.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

The PR spans infrastructure automation and a substantial computation-layer refactoring. The infrastructure changes (dynamic port binding, env script, npm integration) are straightforward. The PMC refactoring is dense: three new calculator classes with multiple interdependencies, removal of ~100 lines of prior repository logic, and test suite restructuring. Review requires understanding the prior single-class computation flow, the new multi-class delegation pattern, heart-rate/power-TSS priority logic, regression modeling, EWMA window calculations, and test assertion updates. Multiple files interact (calculator orchestration, repository delegation, test fixtures); changes are heterogeneous across implementation, types, and test patterns.

Possibly related PRs

  • Asherlc/dofek#1116: Updates Redis host binding in docker-compose.yml to use ${REDIS_PORT...} on 127.0.0.1, overlapping with this PR's port-parameterization strategy.
  • Asherlc/dofek#1088: Changes ClickHouse service port mappings from fixed to environment-driven configuration, directly affecting the same CLICKHOUSE_*_PORT parameterization in this PR.
  • Asherlc/dofek#1075: Modifies .env.example and docker-compose.yml ClickHouse/db URL and port configuration, aligning with this PR's centralized env-generation approach.

Suggested labels

area/server, area/infra, type/refactor

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title is in imperative mood, 54 characters (under 70), lacks unnecessary area prefix (applies across server and infrastructure), and has no trailing punctuation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Storybook previews for 8d89b585 are ready:

This comment updates automatically on each PR push.

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions

Copy link
Copy Markdown
Contributor

Review app is ready:

This environment runs on a dedicated Hetzner server for PR #1176 and updates on each push.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/compose-env.ts`:
- Around line 117-118: The DATABASE_URL and CLICKHOUSE_URL are built using
dotenvEscape(postgresPassword) and dotenvEscape(clickHousePassword), but
dotenvEscape is not URL-safe so passwords containing @ : / ? # will break URL
parsing; replace the dotenvEscape usage for the password components with proper
URL-encoding (e.g. use encodeURIComponent or an equivalent URL-encoding helper)
when constructing DATABASE_URL and CLICKHOUSE_URL so the credentials are
percent-encoded and the resulting URLs remain valid.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 220eeef5-1b9c-45b1-ba0a-8672deeb7320

📥 Commits

Reviewing files that changed from the base of the PR and between 1569130 and e85216b.

📒 Files selected for processing (14)
  • .env.example
  • AGENTS.md
  • README.md
  • docker-compose.yml
  • package.json
  • packages/server/src/repositories/pmc-chart-calculator.test.ts
  • packages/server/src/repositories/pmc-chart-calculator.ts
  • packages/server/src/repositories/pmc-ewma-calculator.test.ts
  • packages/server/src/repositories/pmc-ewma-calculator.ts
  • packages/server/src/repositories/pmc-repository.test.ts
  • packages/server/src/repositories/pmc-repository.ts
  • packages/server/src/repositories/pmc-training-load-calculator.test.ts
  • packages/server/src/repositories/pmc-training-load-calculator.ts
  • scripts/compose-env.ts

Comment thread scripts/compose-env.ts Outdated
@surmado-code-review

surmado-code-review Bot commented May 25, 2026 •

Copy link
Copy Markdown

Automated Checks (advisory, non-blocking)

✅ All checks passed.


Surmado Code Review — Free tier limit reached

You've used all 10 free reviews this month. Deterministic checks (secrets, model strings) still ran above.

Upgrade to the Paid plan for 100 reviews/month + $15 per additional 100: https://app.surmado.com/checkout?plan=pr_review_starter

Or wait until your next monthly window for 10 more free reviews.


Surmado Code Review (v1.2-mt)

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 15 files

Confidence score: 3/5

  • There is a concrete user-impacting risk in scripts/compose-env.ts: dotenvEscape does not escape $, so values can be shell-expanded when .env.local is sourced, potentially corrupting secrets like passwords.
  • Given the issue’s medium-high severity (6/10) and solid confidence (7/10), this looks like a real regression risk rather than a cosmetic concern.
  • Pay close attention to scripts/compose-env.ts and with-env.sh - ensure env values containing $ are preserved literally when writing and sourcing .env.local.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Fix all with cubic | Re-trigger cubic

Comment thread scripts/compose-env.ts
@gitguardian

gitguardian Bot commented May 25, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 2 files (changes from recent commits).

Requires human review: This PR refactors core PMC chart computation logic into separate classes, which is a structural change with potential for subtle bugs despite added tests; such refactors require human review to ensure correctness and preserve existing behavior.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Requires human review: This PR performs a significant refactor of the PMC chart computation, splitting monolithic repository logic into multiple new calculator classes with corresponding tests, while also adding a new Docker Compose port resolution script and modifying infrastructure configuration; given the 2600+...

Re-trigger cubic

@Asherlc
Asherlc force-pushed the Asherlc/split-slow-stryker-files branch from bc6ef7d to 2fe903b Compare May 25, 2026 17:33
@Asherlc
Asherlc force-pushed the Asherlc/split-slow-stryker-files branch from 2fe903b to 2a3cd32 Compare May 25, 2026 17:35

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Requires human review: This PR includes a significant code refactor that splits PMC chart computation into new classes and modifies docker-compose port bindings, both of which carry moderate risk of subtle issues even with the new tests, so human review is warranted.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 3 files (changes from recent commits).

Requires human review: The PR refactors core performance calculation logic (PMC chart, training load, EWMA) into new classes, which, despite preserved test coverage and no detected issues, introduces risk of subtle bugs in a critical business path that computes training stress, threshold power, and chart data—such...

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 6 files (changes from recent commits).

Requires human review: This PR refactors core PMC training-load computation into new calculator classes and adds an infrastructure script for Docker compose port management, both of which are high-impact changes that require human review to ensure correctness and safety.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread packages/server/src/repositories/pmc-repository.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Requires human review: This PR involves substantial refactoring of core business logic (PMC chart calculation) and changes to Docker infrastructure and scripts, which carry moderate to high risk and require human review despite the AI finding no issues.

Re-trigger cubic

@Asherlc
Asherlc merged commit be69a7f into main May 25, 2026
69 checks passed
@Asherlc
Asherlc deleted the Asherlc/split-slow-stryker-files branch May 25, 2026 18:58
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