Skip to content

test: setup ephemeral Bluesky AppView for testing #74

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

shuuji3
Copy link
Collaborator

@shuuji3 shuuji3 commented Feb 24, 2025

resolve #73

Copy link

netlify bot commented Feb 24, 2025

Deploy Preview for tsky failed.

Name Link
🔨 Latest commit 3c20b5d
🔍 Latest deploy log https://app.netlify.com/sites/tsky/deploys/67e56ccb661ce300087b5eab

Copy link
Contributor

github-actions bot commented Feb 24, 2025

Coverage Report for ./packages/client/

Status Category Percentage Covered / Total
🔵 Lines 13.64% 52 / 381
🔵 Statements 13.13% 52 / 396
🔵 Functions 9.6% 17 / 177
🔵 Branches 14.45% 12 / 83
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/client/globalSetup.ts 0% 100% 0% 0% 18-92
Generated in workflow #228 for commit 778f858 by the Vitest Coverage Report Action

@shuuji3 shuuji3 marked this pull request as ready for review February 25, 2025 14:58
@shuuji3 shuuji3 force-pushed the shuuji3/test/setup-bsky-appview branch 2 times, most recently from 9ce1b37 to 778f858 Compare March 12, 2025 14:45
@shuuji3
Copy link
Collaborator Author

shuuji3 commented Mar 12, 2025

OK, the new test is working as expected!

When running the test, the test script runs the ephemeral postgres and redis containers with ephemeral components. Those containers are automatically stopped and removed after running all unit tests.

Run pnpm -r test:coverage
  
Scope: 5 of 6 workspace projects
packages/client test:coverage$ bash ../internal/dev-infra/with-test-redis-and-db.sh vitest --coverage
packages/client test:coverage:  redis_test Pulling 
packages/client test:coverage:  db_test Pulling 
(...)
packages/client test:coverage:  RUN  v3.0.6 /home/runner/work/tsky/tsky/packages/client
packages/client test:coverage:       Coverage enabled with istanbul
packages/client test:coverage: 🌐 Created test network:
packages/client test:coverage: - pds: http://localhost:36279
packages/client test:coverage: - plc: http://localhost:43351
packages/client test:coverage: 🙋 Created new account: @alice.test
packages/client test:coverage: 🙋 Created new account: @bob.test
packages/client test:coverage:  ✓ src/tsky.test.ts (2 tests) 778ms
packages/client test:coverage:    ✓ createAgent > can create agent for Alice 417ms
packages/client test:coverage:    ✓ createAgent > can resume from stored session 360ms
packages/client test:coverage:  ✓ src/profile.test.ts (2 tests) 1092ms
packages/client test:coverage:    ✓ profile > Getting alice's profile 619ms
packages/client test:coverage:    ✓ profile > Getting bob's profile 472ms
packages/client test:coverage:  ✓ src/preferences.test.ts (2 tests) 1162ms
packages/client test:coverage:    ✓ preferences > .get() 574ms
packages/client test:coverage:    ✓ preferences > .set() 587ms
packages/client test:coverage:  Test Files  3 passed (3)
packages/client test:coverage:       Tests  6 passed (6)
packages/client test:coverage:    Start at  14:41:54
packages/client test:coverage:    Duration  7.26s (transform 663ms, setup 0ms, collect 1.57s, tests 3.03s, environment 1ms, prepare 279ms)
packages/client test:coverage:  % Coverage report from istanbul
packages/client test:coverage: ------------------|---------|----------|---------|---------|--------------------
packages/client test:coverage: File              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s  
packages/client test:coverage: ------------------|---------|----------|---------|---------|--------------------
packages/client test:coverage: All files         |   13.13 |    14.45 |     9.6 |   13.64 |                    
packages/client test:coverage:  client           |       0 |      100 |       0 |       0 |                    
packages/client test:coverage:   globalSetup.ts  |       0 |      100 |       0 |       0 | 18-81              
packages/client test:coverage:  client/src       |   14.48 |     16.9 |   10.17 |   15.04 |                    
packages/client test:coverage:   agent.ts        |   11.92 |     12.5 |    8.17 |   12.34 | ...,1245,1252-1315 
packages/client test:coverage:   client.ts       |   27.77 |        0 |   42.85 |   31.25 | 61-138             
packages/client test:coverage:   tsky.ts         |     100 |    83.33 |     100 |     100 | 18                 
packages/client test:coverage:  client/src/utils |    4.54 |        0 |       0 |       5 |                    
packages/client test:coverage:   paginator.ts    |       0 |        0 |       0 |       0 | 6-47               
packages/client test:coverage:   parse.ts        |   14.28 |        0 |       0 |   16.66 | 10-14              
packages/client test:coverage: ------------------|---------|----------|---------|---------|--------------------
packages/client test:coverage:  Container dev-infra-db_test-1  Stopping
packages/client test:coverage:  Container dev-infra-redis_test-1  Stopping
packages/client test:coverage:  Container dev-infra-db_test-1  Stopped
packages/client test:coverage:  Container dev-infra-redis_test-1  Stopped
packages/client test:coverage: Going to remove dev-infra-db_test-1, dev-infra-redis_test-1
packages/client test:coverage:  Container dev-infra-redis_test-1  Removing
packages/client test:coverage:  Container dev-infra-db_test-1  Removing
packages/client test:coverage:  Container dev-infra-redis_test-1  Removed
packages/client test:coverage:  Container dev-infra-db_test-1  Removed
packages/client test:coverage: Done

https://github.com/tsky-dev/tsky/actions/runs/13814249724/job/38643163254?pr=74#step:6:1

@shuuji3 shuuji3 force-pushed the shuuji3/test/setup-bsky-appview branch from 778f858 to 7c94f9a Compare March 27, 2025 15:17
@shuuji3
Copy link
Collaborator Author

shuuji3 commented Mar 30, 2025

There is an error in the generic type TypeUnion, and it stems from one corner case where refs for union type is an empty array here: https://github.com/bluesky-social/atproto/blob/713a52d4dc9a242fd066e0cbd21934ba0367366e/lexicons/tools/ozone/moderation/defs.json#L226-L229

I searched the generated defs.json in tsky repository (/packages/lexicons/lexicons/tools/ozone/moderation/defs.json), but all other union type records have a non-empty array for refs.

Probably we need to enhance TypeUnion to accept empty array. TypeUnion is hard coded here (from atcute):

/** Creates a union of objects discriminated by $type */
export type TypeUnion<T extends TypedBase> = T extends any ? Typed<T, string> : never;

@shuuji3
Copy link
Collaborator Author

shuuji3 commented Mar 30, 2025

I suspected that the empty refs: [] might be invalid, but this is the valid schema, according to the official docs:

A union schema definition with no refs is allowed and similar to unknown, as long as the closed flag is false (the default). The main difference is that the data would be required to have the $type field. An empty refs list with closed set to true is an invalid schema.

https://atproto.com/ja/specs/lexicon

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.

Setup ephemeral Bluesky AppView for testing
1 participant