forked from ColeMurray/background-agents
-
Notifications
You must be signed in to change notification settings - Fork 0
chore: shrink the fork's conflict surface in upstream-owned files #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NicolasWalter
wants to merge
1
commit into
main
Choose a base branch
from
chore/shrink-conflict-surface-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Primo's sandbox-creation guarantees, kept out of upstream's test modules. | ||
|
|
||
| Upstream's `test_build_sandbox.py` and `test_sandbox_resources.py` churn on | ||
| nearly every sync, so fork assertions live here instead — a file upstream will | ||
| never touch and git will never have to merge. | ||
| """ | ||
|
|
||
| from unittest.mock import AsyncMock | ||
|
|
||
| import pytest | ||
|
|
||
| from src.images.primo_overlay import PRIMO_SANDBOX_COMMAND | ||
| from src.sandbox.manager import SandboxConfig, SandboxManager | ||
|
|
||
|
|
||
| def _fake_create(captured: dict): | ||
| """Fake `Sandbox.create` that records the argv and kwargs it was called with.""" | ||
|
|
||
| async def fake_create_aio(*args, **kwargs): | ||
| captured["args"] = args | ||
| captured["kwargs"] = kwargs | ||
|
|
||
| class FakeSandbox: | ||
| object_id = "obj-primo-1" | ||
| stdout = None | ||
|
|
||
| return FakeSandbox() | ||
|
|
||
| fake_create_aio.aio = fake_create_aio | ||
| return fake_create_aio | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_build_sandbox_starts_postgres_before_sandbox_runtime(monkeypatch): | ||
| captured: dict = {} | ||
| monkeypatch.setattr("src.sandbox.manager.modal.Sandbox.create", _fake_create(captured)) | ||
|
|
||
| await SandboxManager().create_build_sandbox(repo_owner="acme", repo_name="my-repo") | ||
|
|
||
| assert captured["args"] == PRIMO_SANDBOX_COMMAND | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_build_sandbox_for_core_uses_vm_runtime_with_ci_sized_resources(monkeypatch): | ||
| captured: dict = {} | ||
| monkeypatch.setattr("src.sandbox.manager.modal.Sandbox.create", _fake_create(captured)) | ||
|
|
||
| await SandboxManager().create_build_sandbox(repo_owner="primo-devs", repo_name="core") | ||
|
|
||
| assert captured["kwargs"]["cpu"] == 2.0 | ||
| assert captured["kwargs"]["memory"] == 8192 | ||
| assert captured["kwargs"]["experimental_options"] == {"vm_runtime": True} | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_session_sandbox_starts_postgres_before_sandbox_runtime(monkeypatch): | ||
| captured: dict = {} | ||
| monkeypatch.setattr("src.sandbox.manager.modal.Sandbox.create", _fake_create(captured)) | ||
| monkeypatch.setattr( | ||
| SandboxManager, | ||
| "_resolve_and_setup_tunnels", | ||
| AsyncMock(return_value=(None, None, None)), | ||
| ) | ||
|
|
||
| await SandboxManager().create_sandbox(SandboxConfig(repo_owner="acme", repo_name="my-repo")) | ||
|
|
||
| assert captured["args"] == PRIMO_SANDBOX_COMMAND | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_session_sandbox_for_core_lets_explicit_resources_override_vm_defaults(monkeypatch): | ||
| captured: dict = {} | ||
| monkeypatch.setattr("src.sandbox.manager.modal.Sandbox.create", _fake_create(captured)) | ||
| monkeypatch.setattr( | ||
| SandboxManager, | ||
| "_resolve_and_setup_tunnels", | ||
| AsyncMock(return_value=(None, None, None)), | ||
| ) | ||
|
|
||
| await SandboxManager().create_sandbox( | ||
| SandboxConfig( | ||
| repo_owner="primo-devs", | ||
| repo_name="core", | ||
| settings={"cpuCores": 3, "memoryMib": 6144}, | ||
| ) | ||
| ) | ||
|
|
||
| assert captured["kwargs"]["cpu"] == 3.0 | ||
| assert captured["kwargs"]["memory"] == 6144 | ||
| assert captured["kwargs"]["experimental_options"] == {"vm_runtime": True} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /** | ||
| * Primo's classifier-prompt guarantees, kept out of upstream's `index.test.ts`. | ||
| * | ||
| * That file churns on nearly every sync, so fork assertions live here instead — | ||
| * a file upstream will never touch and git will never have to merge. | ||
| */ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import type { Env, RepoConfig } from "../types"; | ||
|
|
||
| const { | ||
| mockMessagesCreate, | ||
| mockGetAvailableRepos, | ||
| mockBuildRepoDescriptions, | ||
| mockGetRoutingRules, | ||
| mockGetAvailableEnvironments, | ||
| } = vi.hoisted(() => ({ | ||
| mockMessagesCreate: vi.fn(), | ||
| mockGetAvailableRepos: vi.fn(), | ||
| mockBuildRepoDescriptions: vi.fn(), | ||
| mockGetRoutingRules: vi.fn(), | ||
| mockGetAvailableEnvironments: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@anthropic-ai/sdk", () => ({ | ||
| // vitest 4 only treats `function`/`class` implementations as constructable; | ||
| // an arrow function here throws "is not a constructor" on `new Anthropic()`. | ||
| default: vi.fn().mockImplementation(function () { | ||
| return { messages: { create: mockMessagesCreate } }; | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("./repos", () => ({ | ||
| getAvailableRepos: mockGetAvailableRepos, | ||
| buildRepoDescriptions: mockBuildRepoDescriptions, | ||
| getRoutingRules: mockGetRoutingRules, | ||
| })); | ||
|
|
||
| vi.mock("./environments", async (importOriginal) => ({ | ||
| ...((await importOriginal()) as object), | ||
| getAvailableEnvironments: mockGetAvailableEnvironments, | ||
| getEnvironmentById: vi.fn(), | ||
| })); | ||
|
|
||
| import { RepoClassifier } from "./index"; | ||
| import { PRIMO_CLASSIFIER_INSTRUCTIONS } from "./primo-classifier-instructions"; | ||
|
|
||
| const TEST_REPOS: RepoConfig[] = [ | ||
| { | ||
| id: "acme/prod", | ||
| owner: "acme", | ||
| name: "prod", | ||
| fullName: "acme/prod", | ||
| displayName: "prod", | ||
| description: "Production worker", | ||
| defaultBranch: "main", | ||
| private: true, | ||
| aliases: ["production"], | ||
| keywords: ["worker", "slack"], | ||
| }, | ||
| { | ||
| id: "acme/web", | ||
| owner: "acme", | ||
| name: "web", | ||
| fullName: "acme/web", | ||
| displayName: "web", | ||
| description: "Web application", | ||
| defaultBranch: "main", | ||
| private: true, | ||
| aliases: ["frontend"], | ||
| keywords: ["react", "ui"], | ||
| }, | ||
| ]; | ||
|
|
||
| const TEST_ENV = { | ||
| ANTHROPIC_API_KEY: "test-api-key", | ||
| CLASSIFICATION_MODEL: "claude-haiku-4-5", | ||
| } as Env; | ||
|
|
||
| describe("RepoClassifier (Primo)", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mockGetAvailableRepos.mockResolvedValue(TEST_REPOS); | ||
| mockGetRoutingRules.mockResolvedValue([]); | ||
| mockGetAvailableEnvironments.mockResolvedValue([]); | ||
| mockBuildRepoDescriptions.mockResolvedValue("- acme/prod\n- acme/web"); | ||
| mockMessagesCreate.mockResolvedValue({ | ||
| content: [ | ||
| { | ||
| type: "tool_use", | ||
| id: "toolu_primo", | ||
| name: "classify_target", | ||
| input: { | ||
| targetId: "acme/prod", | ||
| confidence: "high", | ||
| reasoning: "Defaulted to the core repository.", | ||
| alternatives: [], | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| it("adds the Primo default-repository instructions to the LLM prompt", async () => { | ||
| const classifier = new RepoClassifier(TEST_ENV); | ||
| await classifier.classify("estas vivo infeliz?", undefined, "trace-primo"); | ||
|
|
||
| expect(mockMessagesCreate).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| messages: [ | ||
| expect.objectContaining({ | ||
| content: expect.stringContaining(PRIMO_CLASSIFIER_INSTRUCTIONS.trim()), | ||
| }), | ||
| ], | ||
| }) | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Reuse the named Core runtime defaults in these assertions.
Lines 50-52 duplicate the factory resource defaults. Line 90 duplicates the VM runtime options default. Define a named Core VM-options constant in
src.images.primo_overlay, then import that constant and the existing resource constants here. This keeps the tests synchronized with the factory configuration.As per coding guidelines, “Define each default value exactly once in a named constant and import or reuse that constant everywhere.”
Also applies to: 88-90
🤖 Prompt for AI Agents
Source: Coding guidelines