Skip to content

chore(agent/agentcontainers): test current prebuilds integration #19074

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

Merged
merged 7 commits into from
Jul 31, 2025

Conversation

DanielleMaywood
Copy link
Contributor

As it turns out, prebuilds + devcontainers appear to already work together. This PR has created a test that simulates a prebuild claim happening to agentcontainers.API, to see how we handle it.

@DanielleMaywood DanielleMaywood marked this pull request as ready for review July 30, 2025 11:15
@DanielleMaywood
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Jul 30, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jul 30, 2025

📝 Walkthrough

Walkthrough

A new integration-style test, TestDevcontainerPrebuildSupport, was added to validate the behavior of devcontainers during the transition from a prebuild workspace to a claimed workspace. The test checks environment variable correctness, container reuse, and agent creation across both phases using mocks for dependencies.

Changes

Cohort / File(s) Change Summary
Devcontainer Prebuild Support Test
agent/agentcontainers/api_test.go
Added a new test function TestDevcontainerPrebuildSupport to verify devcontainer behavior during prebuild-to-claimed workspace transitions, including environment variable propagation, container reuse, and agent lifecycle checks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Suggested reviewers

  • mafredri
  • johnstcn

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf78966 and 2b97f35.

📒 Files selected for processing (1)
  • agent/agentcontainers/api_test.go (1 hunks)
🔇 Additional comments (1)
agent/agentcontainers/api_test.go (1)

3819-4074: Well-structured integration test for prebuild support!

The test effectively validates the devcontainer lifecycle during workspace claim transitions. The two-phase approach with distinct manifest information and environment variable verification is appropriate.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch danielle/test-devcontainer-prebuild-support

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DanielleMaywood
Copy link
Contributor Author

@coderabbitai generate sequence diagram

Copy link

coderabbitai bot commented Jul 30, 2025

Sequence Diagram for PR

sequenceDiagram
    participant Test as TestDevcontainerPrebuildSupport
    participant API as agentcontainers.API
    participant MockContainer as Mock Container
    participant MockAgent as Mock Agent
    participant MockEnv as Mock Environment

    Note over Test: Setup Phase
    Test->>API: Initialize API with mocks
    Test->>MockContainer: Setup container mock expectations
    Test->>MockAgent: Setup agent mock expectations

    Note over Test: Prebuild Phase Testing
    Test->>API: Create prebuild workspace
    API->>MockContainer: Create devcontainer for prebuild
    MockContainer-->>API: Return container instance
    API->>MockEnv: Set prebuild environment variables
    MockEnv-->>API: Environment configured
    API-->>Test: Prebuild workspace created

    Note over Test: Validation Phase 1
    Test->>API: Verify prebuild environment variables
    API-->>Test: Environment variables correct
    Test->>MockContainer: Verify container creation
    MockContainer-->>Test: Container created as expected

    Note over Test: Transition Phase Testing
    Test->>API: Claim prebuild workspace
    API->>MockContainer: Reuse existing container
    MockContainer-->>API: Container reused successfully
    API->>MockAgent: Create agent for claimed workspace
    MockAgent-->>API: Agent created
    API->>MockEnv: Update environment for claimed state
    MockEnv-->>API: Environment updated
    API-->>Test: Workspace claimed successfully

    Note over Test: Validation Phase 2
    Test->>API: Verify container reuse
    API-->>Test: Same container instance used
    Test->>MockAgent: Verify agent creation
    MockAgent-->>Test: Agent created correctly
    Test->>API: Verify environment transition
    API-->>Test: Environment properly transitioned

    Note over Test: Test Complete
    Test->>Test: Assert all expectations met
Loading

Copy link

coderabbitai bot commented Jul 30, 2025

✅ Actions performed

Sequence diagram generated.

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

I like the principle and see definite value in this test, but worry that the amount of mocking being done here decreases the overall assurances we get.

I don't want to block this PR, but I would suggest adding another test with more of an integration-style approach that uses a well-known devcontainer repo and the 'real' Devcontainer CLI. We couldn't run this by default in CI though, which is the huge value of your current approach.

Comment on lines 3891 to 3896
mDCCLI.EXPECT().Up(gomock.Any(), testDC.WorkspaceFolder, testDC.ConfigPath, gomock.Any()).
Return("test-container-id", nil)

mCCLI.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Containers: []codersdk.WorkspaceAgentContainer{testContainer},
}, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Should these also be InOrder?

@DanielleMaywood
Copy link
Contributor Author

@johnstcn Yeah I can do that. I've refactored the existing test to use the fake* utilities instead of mocking.

I'll make another integration style test (in line with our other docker only tests) as a more thorough test 👍

@DanielleMaywood DanielleMaywood force-pushed the danielle/test-devcontainer-prebuild-support branch from 2db96b0 to 9381e28 Compare July 31, 2025 14:00
@DanielleMaywood
Copy link
Contributor Author

@johnstcn I have added an integration-style test now.

You can run it with

CODER_TEST_USE_DOCKER=1 go test ./agent -test.count 1 -test.run TestAgent_DevcontainerPrebuildClaim

@DanielleMaywood DanielleMaywood merged commit ddb5b87 into main Jul 31, 2025
31 checks passed
@DanielleMaywood DanielleMaywood deleted the danielle/test-devcontainer-prebuild-support branch July 31, 2025 14:31
@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants