Skip to content

Feat/normalize adapter behavior#108

Open
jaysomani wants to merge 14 commits into
utopia-php:mainfrom
jaysomani:feat/normalize-adapter-behavior
Open

Feat/normalize adapter behavior#108
jaysomani wants to merge 14 commits into
utopia-php:mainfrom
jaysomani:feat/normalize-adapter-behavior

Conversation

@jaysomani
Copy link
Copy Markdown
Contributor

@jaysomani jaysomani commented Jun 1, 2026

Normalizes adapter behavior to enable shared Base tests:
Adapter fixes:

GitLab::searchRepositories — was returning flat array, now returns {items, total} consistent with Gitea/GitHub
GitLab::searchRepositories — was returning [] for invalid owner, now returns {items: [], total: 0}
GitHub::searchRepositories — was throwing for invalid owner, now returns empty results
GitHub::updateCommitStatus — was silently ignoring API errors, now throws on failure

Tests moved to Base:

testUpdateCommitStatusWithInvalidCommit
testUpdateCommitStatusWithNonExistingRepository
testSearchRepositoriesNoResults
testSearchRepositoriesInvalidOwner

Depends on: feat/unified-base-tests

@jaysomani jaysomani marked this pull request as ready for review June 1, 2026 07:58
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fb650bac0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/VCS/Adapter/GitHubTest.php Outdated
$this->markTestSkipped('GitHub adapter does not support getUser by username');
}

public function testGetOwnerName(): void
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove duplicate GitHub owner-name test

This adds a second testGetOwnerName() method to GitHubTest while the same method already exists earlier in the class, so PHP cannot even load the test file (php -l tests/VCS/Adapter/GitHubTest.php reports Cannot redeclare Utopia\Tests\Adapter\GitHubTest::testGetOwnerName()). Any PHPUnit run that includes this file will fail before executing tests until one of the duplicate methods is removed or renamed.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Greptile Summary

This PR normalizes searchRepositories and updateCommitStatus behavior across adapters so that a shared set of Base tests can cover all three platforms. GitLab now returns {items, total} from searchRepositories (using the X-Total header), and GitHub no longer throws when the expected key is absent in the search response; GitHub updateCommitStatus now throws on HTTP ≥ 400 instead of silently discarding errors; Gitea getCommitStatuses normalizes the raw status field to state.

  • Adapter fixes: GitLab::searchRepositories returns {items, total} and gracefully returns empty on errors; GitHub::searchRepositories returns empty results for invalid owners; GitHub::updateCommitStatus throws on API failures; GitLab::getOwnerName treats repositoryId = 0 as absent, falling back to /user.
  • Test consolidation: Four tests (testUpdateCommitStatusWithInvalidCommit, testUpdateCommitStatusWithNonExistingRepository, testSearchRepositoriesNoResults, testSearchRepositoriesInvalidOwner) are promoted to Base.php; many adapter-specific tests that are now redundant are removed; setUp is renamed to setupAdapter across adapters.
  • Docker defaults: Admin username default changed from utopia to root for Gitea, Forgejo, and Gogs containers.

Confidence Score: 5/5

The changes are safe to merge; all three adapter fixes correctly align error and empty-result handling, and the shared test suite properly covers the new behavior.

All adapter changes are narrowly scoped: the two GitHub search paths return empty maps instead of throwing, the GitHub status update now propagates API errors, the GitLab search returns the expected envelope shape, and the Gitea statuses normalization maps the API field names correctly. The test consolidation is consistent — adapters that don't support a feature explicitly skip the promoted tests. No data-loss, auth, or contract-breaking issues were found.

The happy path of GitHub::updateCommitStatus has no test coverage after testUpdateCommitStatus was skipped, but this does not affect correctness of the current implementation.

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitHub.php Two searchRepositories paths now return empty result instead of throwing; updateCommitStatus now throws on HTTP >= 400. The third paginated-with-search path still throws (pre-existing, flagged in prior review).
src/VCS/Adapter/Git/GitLab.php searchRepositories now returns {items, total} shape using the x-total response header; getOwnerName condition relaxed to $repositoryId > 0 so that 0 falls back to /user.
src/VCS/Adapter/Git/Gitea.php getCommitStatuses now normalizes Gitea's raw status field to the shared state key, enabling the shared Base test assertions to pass.
tests/VCS/Base.php Four tests promoted from adapter-specific files to Base: testUpdateCommitStatusWithInvalidCommit, testUpdateCommitStatusWithNonExistingRepository, testSearchRepositoriesNoResults, and testSearchRepositoriesInvalidOwner. Base test for searchRepositories now asserts {items, total} shape.
tests/VCS/Adapter/GitLabTest.php Large number of tests moved to Base; testSearchRepositories updated to validate the new {items, total} shape; added testGetOwnerName testing the /user fallback path.
tests/VCS/Adapter/GitHubTest.php Many tests moved to Base; testUpdateCommitStatus is now skipped (getCommitStatuses not implemented for GitHub); skips added for testGetUser/testGetUserWithInvalidUsername.
tests/VCS/Adapter/GiteaTest.php setUp renamed to setupAdapter to match new Base convention; tests moved to Base.
tests/VCS/Adapter/ForgejoTest.php createVCSAdapter/setUp replaced with setupAdapter; inherits shared Base tests via GiteaTest.
tests/VCS/Adapter/GogsTest.php New markTestSkipped calls added for commit-status tests that Gogs doesn't support; testSearchRepositoriesNoResults and testSearchRepositoriesInvalidOwner from Base run without a skip (Gitea/Gogs adapter already returns correct shape).
docker-compose.yml Default admin username for Gitea, Forgejo, and Gogs changed from utopia to root to align with platform defaults that some of their API paths require.

Reviews (4): Last reviewed commit: "fix: restore lost test coverage identifi..." | Re-trigger Greptile

Comment thread src/VCS/Adapter/Git/GitLab.php Outdated
Comment thread tests/VCS/Base.php
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.

Seeing this diff is slightly worrying:

Image

We removed 2k, adding 1k to base. While techincally it could be OK, its a bit scarrry.

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.

I ran agent to do a diff review, here is his comment

Review Findings: Coverage Lost During Test Migration
I compared the upstream main branch against the PR branch (feat/normalize-adapter-behavior), specifically looking for tests removed from adapter-specific files that were not restored in tests/VCS/Base.php. Here are the concrete mistakes I found:

  1. testCreatePrivateRepository — privacy assertion dropped
    Impact: All adapters (GitHub, GitLab, Gitea)
    All three adapter tests previously verified that a private repository was actually created as private:
  • GitHub: $this->assertTrue($result['private'])
  • GitLab: $this->assertSame('private', $result['visibility']) (+ verified via getRepository)
  • Gitea: $this->assertTrue($result['private']) (+ verified via getRepository)
    The migrated test in Base.php only asserts that the result has a name key. It never checks the privacy flag, so a broken adapter that ignores the $private parameter would still pass.
  1. testUpdateCommitStatus — status verification dropped
    Impact: GitLab and Gitea (GitHub already had the weak version)
    Upstream GitLab and Gitea tests called getCommitStatuses() after updateCommitStatus() to confirm the status was recorded:
  • GitLab: asserted state array contained 'success'
  • Gitea: looped through statuses, found the 'ci/tests' context, and asserted status === 'success' and description === 'Tests passed'
    The migrated test in Base.php only asserts $this->assertTrue(true) after the update call. It does not verify the commit status was persisted at all.
  1. testCreateRepositoryWithInvalidName — removed from Gitea/Forgejo, not added to Base
    Impact: Gitea and Forgejo
    Gitea upstream had a negative test for invalid repository names ('invalid name with spaces'). It was deleted in the PR and never moved to Base.php.
    GitLabTest still keeps its own copy, but GiteaTest (and ForgejoTest, which extends it) no longer runs it.
  2. testCreateRepository — public visibility assertion dropped
    Impact: GitHub, GitLab, Gitea
    All adapter-specific tests previously asserted the created public repo was actually public:
  • GitHub: $this->assertFalse($result['private'])
  • GitLab: $this->assertFalse($result['visibility'] === 'private')
  • Gitea: $this->assertFalse($result['private'])
    The Base version only checks name and pushed_at, so this coverage is also lost.
  1. testGetOwnerName — null $repositoryId case lost for GitLab
    Impact: GitLab
    GitLab upstream had two tests:
  2. testGetOwnerName() — called getOwnerName('', null) (no repo ID)
  3. testGetOwnerNameWithRepositoryId() — called getOwnerName('', $repositoryId)
    Base only has one test that passes a $repositoryId. The null / no-arg path for GitLab is no longer exercised.
    Summary Table
    Test / Coverage
    Assert repo is private (testCreatePrivateRepository)
    Assert repo is public (testCreateRepository)
    Verify commit status after update (testUpdateCommitStatus)
    Invalid repository name (testCreateRepositoryWithInvalidName)
    getOwnerName('', null)

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.

Please also try from your side, with agent (after fixes), see if on another try he can spot anything else.

Also keep in mind its AI, he can be wrong. If something feels irrelevant to you, feel free to ignore.

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.

CleanShot 2026-06-03 at 13 02 36@2x

@Meldiron Meldiron added the test Enables E2E tests in CI/CD label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Enables E2E tests in CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants