Skip to content

initial unified base tests#106

Open
jaysomani wants to merge 9 commits into
utopia-php:mainfrom
jaysomani:feat/unified-base-tests
Open

initial unified base tests#106
jaysomani wants to merge 9 commits into
utopia-php:mainfrom
jaysomani:feat/unified-base-tests

Conversation

@jaysomani
Copy link
Copy Markdown
Contributor

@jaysomani jaysomani commented May 22, 2026

Migrates all shared adapter tests into Base.php following the dynamic pattern. All tests now create repos dynamically with uniqid() and clean up in finally blocks — no hardcoded owners, repos, or IDs.
Key changes:

Base.php fully rewritten with shared dynamic tests covering repository CRUD, tree, content, branches, commits, clone commands, pull requests, comments, search and owner
All adapter files implement setupAdapter() instead of setUp()
static::$owner and static::$defaultBranch used throughout
Duplicate tests removed from GiteaTest, GitLabTest, GitHubTest
Adapter-specific tests kept only where behavior genuinely differs
getOwnerName made consistent across GitLab and Gitea — requires repositoryId
Admin username changed to root across all adapters for consistency
testListBranchesEmptyRepo skipped in Base — each adapter overrides correctly

@jaysomani jaysomani changed the title inital testing initial unified base tests May 22, 2026
@jaysomani jaysomani marked this pull request as ready for review May 25, 2026 04:34
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: 5f46cf912a

ℹ️ 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/Base.php Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 25, 2026

Greptile Summary

This PR consolidates shared adapter tests into Base.php using a dynamic setup pattern (setupAdapter(), uniqid()-based repo names, finally-block cleanup). Duplicate tests are removed from GiteaTest, GitLabTest, and GitHubTest, and the GitLab getOwnerName fallback to /user is removed in favour of always requiring a repositoryId.

  • Base.php is fully rewritten with ~35 shared dynamic tests covering the full adapter surface; adapter-specific overrides remain only where behaviour genuinely differs.
  • All test files replace setUp()/createVCSAdapter() with a single setupAdapter() method that instantiates the adapter and sets static::$owner.
  • docker-compose.yml changes the default admin username to root for Gitea, Forgejo, and Gogs, aligning with the new testGetUser('root') assertion in Base.

Confidence Score: 5/5

Safe to merge; changes are confined to test infrastructure and one clarifying non-functional tightening of a GitLab adapter method.

The production code change (GitLab getOwnerName) removes a fallback path that was acknowledged as intentionally wrong, and all call sites within the repo now pass a valid repositoryId. The test consolidation is mechanical and well-structured. The two findings are both cosmetic: a stale comment and a missing finally in a Gitea-only test override.

tests/VCS/Adapter/GiteaTest.php — stale comment and missing finally in testGetRepositoryName.

Important Files Changed

Filename Overview
tests/VCS/Base.php Base class fully rewritten with shared dynamic tests; setUp now delegates to abstract setupAdapter(). testCreateRepositoryWithInvalidName was not added to Base so Gitea/GitHub adapters skip it.
src/VCS/Adapter/Git/GitLab.php getOwnerName now throws when repositoryId is null/<=0 instead of falling back to /user endpoint; breaking change acknowledged as intentional.
tests/VCS/Adapter/GiteaTest.php Migrated to setupAdapter(). testGetRepositoryName override is missing a finally block; stale comment in testListBranchesEmptyRepo references a non-existent hardcoded owner.
tests/VCS/Adapter/GitLabTest.php Migrated to setupAdapter(); duplicate tests removed. testCreateRepositoryWithInvalidName now correctly uses expectException.
tests/VCS/Adapter/GitHubTest.php Migrated to setupAdapter(); large number of duplicate tests removed. New testGetOwnerName override correctly uses installationId only.
tests/VCS/Adapter/ForgejoTest.php Cleanly migrated from setUp/createVCSAdapter to setupAdapter(); no issues identified.
tests/VCS/Adapter/GogsTest.php Migrated to setupAdapter() pattern; no issues identified.
docker-compose.yml Admin username default changed from 'utopia' to 'root' for Gitea, Forgejo, and Gogs; aligns with testGetUser('root') in Base.

Reviews (8): Last reviewed commit: "Merge branch 'main' of https://github.co..." | Re-trigger Greptile

Comment thread tests/VCS/Base.php
Comment thread src/VCS/Adapter/Git/GitLab.php
Comment thread tests/VCS/Base.php Outdated
Comment thread tests/VCS/Base.php
Comment thread tests/VCS/Base.php
Comment thread tests/VCS/Base.php Outdated
throw new Exception("repositoryId is required for this adapter");
}

$url = "/user";
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.

Same comment as in PR #108, I dont think we can do this change as it would break Appwrite implementation

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.

Ran agent here too for noticing lost tests, here is result. Might be same as the other PR, I just noticed a lot of changes are similar.

I did a systematic comparison of every test method across the old adapter files, the new adapter files, and the rewritten Base.php. Here are the mistakes I found in the migration:
🔴 Critical: Fatal PHP Error in GitHubTest.php
testGetOwnerName() is declared twice in tests/VCS/Adapter/GitHubTest.php (at lines ~681 and ~779).
PHP will throw a fatal error when the class is loaded:
Fatal error: Cannot redeclare Utopia\Tests\Adapter\GitHubTest::testGetOwnerName()
This is a clear copy-paste artifact from the migration and will prevent the GitHub test suite from running at all.
🟠 Lost Coverage: testCreateRepositoryWithInvalidName
What was removed:
Old GiteaTest had a testCreateRepositoryWithInvalidName() test that verified creating a repo with spaces in the name throws an exception.
Where it went:

  • Removed from GiteaTest (and therefore from ForgejoTest, which extends it).
  • Not added to Base.php.
  • It only survives in GitLabTest.
    Impact:
    GiteaTest and ForgejoTest no longer verify invalid-name rejection. Because this was a shared test (both Gitea and GitLab had it), it should have been moved to Base.php so all adapters run it.
    🟡 Lost Coverage: testGetOwnerNameWithRepositoryId
    What was removed:
    Old GitLabTest had testGetOwnerNameWithRepositoryId(), which:
  1. Created a repository.
  2. Fetched it back via getRepository().
  3. Used that repository ID to call getOwnerName().
    Where it went:
  • Removed from GitLabTest.
  • Not added to Base.php.
    Impact:
    Base.php does have testGetOwnerName(), but it uses the ID returned directly from createRepository(). It does not exercise the getRepository → getOwnerName path, so that specific integration is no longer tested for GitLab.
    🟡 Unsafe Override Left in GiteaTest
    GiteaTest still overrides testGetRepositoryName() even though Base.php now provides a generic version. The Gitea override does not wrap cleanup in try/finally:
    // GiteaTest (current)
    $this->assertTrue($this->vcsAdapter->deleteRepository(static::$owner, $repositoryName));

// Base.php (safer)
try { ... } finally {
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
}
If getRepositoryName() throws, the Gitea override leaks the test repository. This override should be deleted so the safer Base test runs.
🟡 Incomplete Duplicate Removal in GitHubTest
While not fatal, many tests that now exist identically in Base.php are still duplicated in GitHubTest.php (e.g. testGetLatestCommit, testUpdateCommitStatus, testGenerateCloneCommand, testGenerateCloneCommandWithCommitHash, testGenerateCloneCommandWithInvalidRepository). Because they override the Base methods, the unified Base tests are never actually executed for GitHub, which partially defeats the purpose of the migration.
TL;DR
Issue File Severity
Duplicate method testGetOwnerName GitHubTest.php Fatal
testCreateRepositoryWithInvalidName removed, not in Base GiteaTest Coverage lost
testGetOwnerNameWithRepositoryId removed, not in Base GitLabTest Coverage lost
Unsafe testGetRepositoryName override kept GiteaTest Leaks repos on failure

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.

Image

@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