Skip to content

Comments

Add agent rule for integration test database cleanup#67

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-integration-test-rule
Draft

Add agent rule for integration test database cleanup#67
Copilot wants to merge 2 commits intomainfrom
copilot/add-integration-test-rule

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

Without guidance, AI agents adding new entities can forget to update ResetDatabaseAsync or skip extending IntegrationTestBase, causing test pollution across the suite.

Changes

  • .github/agents/integration-tests.md — new agent rule file covering:
    • Every DbSet<T> in ApplicationDbContext must have a matching RemoveRange in ResetDatabaseAsync, children before parents (FK order)
    • All test classes must extend IntegrationTestBase — this is the mechanism that calls ResetDatabaseAsync before each test
    • Entities with shared fixtures (e.g. admin user) need conditional cleanup, not unconditional RemoveRange
    • Reference table of current entities and their FK dependencies for correct deletion ordering
    • Concrete code example for adding a new entity + its cleanup

Example (from the rule)

// 1. Add DbSets to ApplicationDbContext
public DbSet<Foo> Foos => Set<Foo>();
public DbSet<FooItem> FooItems => Set<FooItem>();

// 2. Add cleanup to ResetDatabaseAsync — child before parent
db.FooItems.RemoveRange(db.FooItems);
db.Foos.RemoveRange(db.Foos);

// 3. Test class must extend IntegrationTestBase
public class FooEndpointTests(PostgresContainerFixture postgres)
    : IntegrationTestBase(postgres) { }
Original prompt

This section details on the original issue you should resolve

<issue_title>Test agent rule</issue_title>
<issue_description>Please create an agent rule for integration tests, that ensures that database cleanup method contains all new entities, and that the method is always called.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: inur93 <5747088+inur93@users.noreply.github.com>
Copilot AI changed the title [WIP] Add agent rule for integration tests Add agent rule for integration test database cleanup Feb 24, 2026
Copilot AI requested a review from inur93 February 24, 2026 10:29
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.

Test agent rule

2 participants