Skip to content

refactor(api): remove db type aliases and import sharedauth errors di…#2630

Merged
tvi merged 1 commit into
mainfrom
t/fix-reexpo
May 12, 2026
Merged

refactor(api): remove db type aliases and import sharedauth errors di…#2630
tvi merged 1 commit into
mainfrom
t/fix-reexpo

Conversation

@tvi

@tvi tvi commented May 12, 2026

Copy link
Copy Markdown
Contributor

…rectly

@cursor

cursor Bot commented May 12, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Low risk refactor that only changes error type references, but could break compilation if any remaining code imported the removed db aliases.

Overview
This removes the packages/api/internal/db/apikeys.go type aliases for TeamForbiddenError/TeamBlockedError and switches processCustomErrors in utils/error.go to check against sharedauth.TeamForbiddenError/sharedauth.TeamBlockedError directly; the main risk is any leftover references to the deleted db aliases causing build failures.

Reviewed by Cursor Bugbot for commit b8f739e. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
2609 3 2606 7
View the full list of 8 ❄️ flaky test(s)
github.com/e2b-dev/infra/tests/integration/internal/tests/api/sandboxes::TestUpdateNetworkConfig

Flake rate in main: 76.77% (Passed 138 times, Failed 456 times)

Stack Traces | 42.9s run time
=== RUN   TestUpdateNetworkConfig
=== PAUSE TestUpdateNetworkConfig
=== CONT  TestUpdateNetworkConfig
Executing command curl in sandbox ifb4tb3exsxevc397nuu7
--- FAIL: TestUpdateNetworkConfig (42.92s)
github.com/e2b-dev/infra/tests/integration/internal/tests/api/sandboxes::TestUpdateNetworkConfig/pause_resume_preserves_allow_internet_access_false

Flake rate in main: 77.19% (Passed 133 times, Failed 450 times)

Stack Traces | 4.05s run time
=== RUN   TestUpdateNetworkConfig/pause_resume_preserves_allow_internet_access_false
    sandbox_network_update_test.go:372: Command [curl] output: event:{start:{pid:1354}}
    sandbox_network_update_test.go:372: Command [curl] output: event:{end:{exit_code:35 exited:true status:"exit status 35" error:"exit status 35"}}
    sandbox_network_update_test.go:372: Command [curl] output: event:{start:{pid:1355}}
    sandbox_network_update_test.go:372: Command [curl] output: event:{end:{exit_code:35 exited:true status:"exit status 35" error:"exit status 35"}}
    sandbox_network_update_test.go:391: Command [curl] output: event:{start:{pid:1356}}
    sandbox_network_update_test.go:391: Command [curl] output: event:{data:{stdout:"HTTP/2 302 \r\nx-content-type-options: nosniff\r\nlocation: https://dns.google/\r\ndate: Tue, 12 May 2026 02:40:50 GMT\r\ncontent-type: text/html; charset=UTF-8\r\nserver: HTTP server (unknown)\r\ncontent-length: 216\r\nx-xss-protection: 0\r\nx-frame-options: SAMEORIGIN\r\nalt-svc: h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000\r\n\r\n"}}
    sandbox_network_update_test.go:391: Command [curl] output: event:{end:{exited:true status:"exit status 0"}}
    sandbox_network_update_test.go:391: Command [curl] completed successfully in sandbox ipizmgedn03eh6z34dxon
    sandbox_network_update_test.go:391: 
        	Error Trace:	.../api/sandboxes/sandbox_network_out_test.go:74
        	            				.../api/sandboxes/sandbox_network_update_test.go:60
        	            				.../api/sandboxes/sandbox_network_update_test.go:391
        	Error:      	An error is expected but got nil.
        	Test:       	TestUpdateNetworkConfig/pause_resume_preserves_allow_internet_access_false
        	Messages:   	https://8.8.8.8 should be blocked
--- FAIL: TestUpdateNetworkConfig/pause_resume_preserves_allow_internet_access_false (4.05s)
github.com/e2b-dev/infra/tests/integration/internal/tests/envd::TestBindLocalhost

Flake rate in main: 57.43% (Passed 235 times, Failed 317 times)

Stack Traces | 0s run time
=== RUN   TestBindLocalhost
=== PAUSE TestBindLocalhost
=== CONT  TestBindLocalhost
--- FAIL: TestBindLocalhost (0.00s)
github.com/e2b-dev/infra/tests/integration/internal/tests/envd::TestBindLocalhost/bind_0_0_0_0

Flake rate in main: 63.56% (Passed 129 times, Failed 225 times)

Stack Traces | 7.34s run time
=== RUN   TestBindLocalhost/bind_0_0_0_0
=== PAUSE TestBindLocalhost/bind_0_0_0_0
=== CONT  TestBindLocalhost/bind_0_0_0_0
    localhost_bind_test.go:69: Command [python] output: event:{start:{pid:1249}}
Executing command python in sandbox ityyk0d9s62t1kvby06rl
    localhost_bind_test.go:90: 
        	Error Trace:	.../tests/envd/localhost_bind_test.go:90
        	Error:      	Not equal: 
        	            	expected: 200
        	            	actual  : 502
        	Test:       	TestBindLocalhost/bind_0_0_0_0
        	Messages:   	Unexpected status code 502 for bind address 0.0.0.0
--- FAIL: TestBindLocalhost/bind_0_0_0_0 (7.34s)
github.com/e2b-dev/infra/tests/integration/internal/tests/envd::TestBindLocalhost/bind_::1

Flake rate in main: 65.32% (Passed 129 times, Failed 243 times)

Stack Traces | 7.3s run time
=== RUN   TestBindLocalhost/bind_::1
=== PAUSE TestBindLocalhost/bind_::1
=== CONT  TestBindLocalhost/bind_::1
Executing command python in sandbox iydox4fn1dond2x50jlfg
    localhost_bind_test.go:69: Command [python] output: event:{start:{pid:1249}}
    localhost_bind_test.go:90: 
        	Error Trace:	.../tests/envd/localhost_bind_test.go:90
        	Error:      	Not equal: 
        	            	expected: 200
        	            	actual  : 502
        	Test:       	TestBindLocalhost/bind_::1
        	Messages:   	Unexpected status code 502 for bind address ::1
--- FAIL: TestBindLocalhost/bind_::1 (7.30s)
github.com/e2b-dev/infra/tests/integration/internal/tests/envd::TestBindLocalhost/bind_localhost

Flake rate in main: 65.42% (Passed 129 times, Failed 244 times)

Stack Traces | 7.81s run time
=== RUN   TestBindLocalhost/bind_localhost
=== PAUSE TestBindLocalhost/bind_localhost
=== CONT  TestBindLocalhost/bind_localhost
Executing command python in sandbox ii2tzt7pv1fjjunhn8yer
    localhost_bind_test.go:69: Command [python] output: event:{start:{pid:1249}}
    localhost_bind_test.go:90: 
        	Error Trace:	.../tests/envd/localhost_bind_test.go:90
        	Error:      	Not equal: 
        	            	expected: 200
        	            	actual  : 502
        	Test:       	TestBindLocalhost/bind_localhost
        	Messages:   	Unexpected status code 502 for bind address localhost
--- FAIL: TestBindLocalhost/bind_localhost (7.81s)
github.com/e2b-dev/infra/tests/integration/internal/tests/orchestrator::TestSandboxMemoryIntegrity

Flake rate in main: 66.43% (Passed 139 times, Failed 275 times)

Stack Traces | 76s run time
=== RUN   TestSandboxMemoryIntegrity
=== PAUSE TestSandboxMemoryIntegrity
=== CONT  TestSandboxMemoryIntegrity
    sandbox_memory_integrity_test.go:26: Build completed successfully
--- FAIL: TestSandboxMemoryIntegrity (75.96s)
github.com/e2b-dev/infra/tests/integration/internal/tests/orchestrator::TestSandboxMemoryIntegrity/tmpfs_hash

Flake rate in main: 67.59% (Passed 129 times, Failed 269 times)

Stack Traces | 30.9s run time
=== RUN   TestSandboxMemoryIntegrity/tmpfs_hash
=== PAUSE TestSandboxMemoryIntegrity/tmpfs_hash
=== CONT  TestSandboxMemoryIntegrity/tmpfs_hash
    sandbox_memory_integrity_test.go:70: Command [bash] output: event:{start:{pid:1250}}
    sandbox_memory_integrity_test.go:70: Command [bash] output: event:{data:{stdout:"Total memory: 985 MB\nUsed memory before tmpfs mount: 184 MB\nFree memory before tmpfs mount: 800 MB\nMemory to use in integrity test (80% of free, min 64MB): 640 MB\n"}}
Executing command bash in sandbox ijqekbpj6mhvwlfgeshp1 (user: root)
    sandbox_memory_integrity_test.go:70: Command [bash] output: event:{data:{stderr:"640+0 records in\n640+0 records out\n671088640 bytes (671 MB, 640 MiB) copied, 3.27008 s, 205 MB/s\n"}}
    sandbox_memory_integrity_test.go:70: Command [bash] output: event:{data:{stderr:"\tCommand being timed: \"dd if=/dev/urandom of=/mnt/testfile bs=1M count=640\"\n\tUser time (seconds): 0.00\n\tSystem time (seconds): 3.25\n\tPercent of CPU this job got: 99%\n\tElapsed (wall clock) time (h:mm:ss or m:ss): 0:03.27\n\tAverage shared text size (kbytes): 0\n\tAverage unshared data size (kbytes): 0\n\tAverage stack size (kbytes): 0\n\tAverage total size (kbytes): 0\n\tMaximum resident set size (kbytes): 2596\n\tAverage resident set size (kbytes): 0\n\tMajor (requiring I/O) page faults: 2\n\tMinor (reclaiming a frame) page faults: 341\n\tVoluntary context switches: 3\n\tInvoluntary context switches: 15\n\tSwaps: 0\n\tFile system inputs: 176\n\tFile system outputs: 0\n\tSocket messages sent: 0\n\tSocket messages received: 0\n\tSignals delivered: 0\n\tPage size (bytes): 4096\n\tExit status: 0\n"}}
    sandbox_memory_integrity_test.go:70: Command [bash] output: event:{data:{stdout:"Used memory after tmpfs mount and file fill: 830 MB\n"}}
    sandbox_memory_integrity_test.go:70: Command [bash] output: event:{end:{exited:true  status:"exit status 0"}}
    sandbox_memory_integrity_test.go:70: Command [bash] completed successfully in sandbox ii0ix32o1hjuloh3ixged
Executing command bash in sandbox ii0ix32o1hjuloh3ixged (user: root)
    sandbox_memory_integrity_test.go:74: Command [bash] output: event:{start:{pid:1267}}
    sandbox_memory_integrity_test.go:74: Command [bash] output: event:{data:{stdout:"d3841054cc6c478b1eb200a9544239bcfacf2c6f1b5c21c131b994acd9f7e8bd\n"}}
    sandbox_memory_integrity_test.go:74: Command [bash] output: event:{end:{exited:true  status:"exit status 0"}}
    sandbox_memory_integrity_test.go:74: Command [bash] completed successfully in sandbox ii0ix32o1hjuloh3ixged
Executing command bash in sandbox ii0ix32o1hjuloh3ixged (user: root)
    sandbox_memory_integrity_test.go:99: Command [bash] output: event:{start:{pid:1270}}
    sandbox_memory_integrity_test.go:100: 
        	Error Trace:	.../tests/orchestrator/sandbox_memory_integrity_test.go:100
        	Error:      	Received unexpected error:
        	            	failed to execute command bash in sandbox ii0ix32o1hjuloh3ixged: invalid_argument: protocol error: incomplete envelope: unexpected EOF
        	Test:       	TestSandboxMemoryIntegrity/tmpfs_hash
--- FAIL: TestSandboxMemoryIntegrity/tmpfs_hash (30.94s)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, straightforward refactor that removes unused type aliases and uses the underlying sharedauth types directly.

Extended reasoning...

Overview

This PR deletes packages/api/internal/db/apikeys.go (which contained only two type aliases) and updates processCustomErrors in packages/api/internal/utils/error.go to reference sharedauth.TeamForbiddenError/sharedauth.TeamBlockedError directly instead of via the db aliases. The db import in error.go is removed as it is no longer needed.

Security risks

None. This is a pure refactor with no runtime behavior change — errors.As against type aliases behaves identically to the underlying type, since Go type aliases are the same type.

Level of scrutiny

Minimal — this is a mechanical cleanup of an indirection layer. I verified with grep that there are no remaining references to db.TeamForbiddenError or db.TeamBlockedError in the packages/api tree, so the change should compile cleanly.

Other factors

The PR is two files, fewer than 15 lines of effective diff, and the cursor bot review flagged it low-risk. No reviewer comments are outstanding.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

The pull request removes redundant error type aliases in the internal db package and updates the error processing logic to use the sharedauth package directly. I have no feedback to provide.

@tvi tvi merged commit f71b4c3 into main May 12, 2026
53 checks passed
@tvi tvi deleted the t/fix-reexpo branch May 12, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants