Skip to content

Commit b71fb04

Browse files
Merge branch 'main' into feat/post
2 parents 3e0f2ef + 5cb690f commit b71fb04

File tree

23 files changed

+4508
-138
lines changed

23 files changed

+4508
-138
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
pull-requests: write
2121
steps:
2222
- uses: actions/checkout@v4
23-
- run: corepack enable
23+
- uses: pnpm/action-setup@v4
2424
- uses: actions/setup-node@v4
2525
with:
2626
node-version: 20

.github/workflows/update-lexicons.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
push:
77
branches:
88
- main
9+
schedule:
10+
- cron: '0 * * * *'
911
workflow_dispatch: {}
1012
merge_group: {}
1113

@@ -19,7 +21,7 @@ jobs:
1921
- uses: actions/checkout@v4
2022
with:
2123
ref: ${{ github.head_ref || github.ref_name }}
22-
- run: corepack enable
24+
- uses: pnpm/action-setup@v4
2325
- uses: actions/setup-node@v4
2426
with:
2527
node-version: 20

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"scripts": {
1414
"dev": "pnpm run -r dev",
1515
"build": "pnpm run -r build",
16-
"prepare": "pnpm build",
16+
"prepare": "pnpm --filter !@tsky/docs build",
1717
"docs:dev": "pnpm run --filter @tsky/docs dev",
1818
"docs:build": "pnpm run --filter @tsky/docs build",
1919
"docs:preview": "pnpm run --filter @tsky/docs preview",

packages/client/globalSetup.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { TestProject } from 'vitest/node';
2+
3+
import { CredentialManager, XRPC } from '@atcute/client';
4+
import { TestNetwork } from '@atcute/internal-dev-env';
5+
6+
let network: TestNetwork;
7+
8+
export async function setup(project: TestProject) {
9+
network = await TestNetwork.create({});
10+
console.log(
11+
`🌐 Created test network:\n- pds: ${network.pds.url}\n- plc: ${network.plc.url}`,
12+
);
13+
14+
const manager = new CredentialManager({ service: network.pds.url });
15+
const rpc = new XRPC({
16+
handler: manager,
17+
});
18+
19+
await createAccount(rpc, 'alice.test');
20+
await createAccount(rpc, 'bob.test');
21+
22+
project.provide('testPdsUrl', network.pds.url);
23+
project.provide('testPlcUrl', network.plc.url);
24+
}
25+
26+
export async function teardown() {
27+
await network.close();
28+
}
29+
30+
const createAccount = async (rpc: XRPC, handle: string) => {
31+
await rpc.call('com.atproto.server.createAccount', {
32+
data: {
33+
handle: handle,
34+
email: `${handle}@example.com`,
35+
password: 'password',
36+
},
37+
});
38+
console.log(`🙋 Created new account: @${handle}`);
39+
};
40+
41+
declare module 'vitest' {
42+
export interface ProvidedContext {
43+
testPdsUrl: string;
44+
testPlcUrl: string;
45+
}
46+
}

packages/client/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
"@atcute/client": "^2.0.6"
3636
},
3737
"devDependencies": {
38+
"@atcute/internal-dev-env": "workspace:*",
3839
"@tsky/lexicons": "workspace:*",
3940
"@vitest/coverage-istanbul": "2.1.6",
4041
"globals": "^15.12.0",
4142
"pkgroll": "^2.5.1",
4243
"tsx": "^4.19.2",
43-
"typescript": "^5.7.2",
44-
"vitest": "^2.1.6"
44+
"typescript": "catalog:",
45+
"vitest": "^3.0.5"
4546
}
4647
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { describe, expect, inject, it } from 'vitest';
2+
3+
import type { AtpSessionData } from '@atcute/client';
4+
5+
import { createAgent } from '~/tsky';
6+
7+
describe('createAgent', () => {
8+
it('can create agent for Alice', async () => {
9+
const agent = await createAgent(
10+
{
11+
identifier: 'alice.test',
12+
password: 'password',
13+
},
14+
{ service: inject('testPdsUrl') },
15+
);
16+
expect(agent.session).not.toBe(undefined);
17+
expect(agent.session?.handle).toBe('alice.test');
18+
expect(agent.session?.email).toBe('alice.test@example.com');
19+
});
20+
21+
it('can resume from stored session', async () => {
22+
let session: AtpSessionData;
23+
{
24+
const agent = await createAgent(
25+
{
26+
identifier: 'alice.test',
27+
password: 'password',
28+
},
29+
{ service: inject('testPdsUrl') },
30+
);
31+
expect(agent.session).toBeDefined();
32+
session = agent.session as AtpSessionData;
33+
}
34+
35+
{
36+
const agent = await createAgent(
37+
{ session },
38+
{ service: inject('testPdsUrl') },
39+
);
40+
expect(agent.session).not.toBe(undefined);
41+
expect(agent.session?.handle).toBe('alice.test');
42+
expect(agent.session?.email).toBe('alice.test@example.com');
43+
}
44+
});
45+
});

packages/client/src/tsky/tsky.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ export async function createAgent(
1313
options ?? { service: 'https://bsky.social' },
1414
);
1515

16-
if ('session' in credentials) manager.resume(credentials.session);
17-
else await manager.login(credentials);
16+
if ('session' in credentials) {
17+
await manager.resume(credentials.session);
18+
} else {
19+
await manager.login(credentials);
20+
}
1821

1922
return new Agent(manager);
2023
}

packages/client/test-utils.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { inject } from 'vitest';
2+
3+
import type { Agent } from '~/agent';
4+
import { createAgent } from '~/tsky';
5+
6+
type Handle = 'alice.test' | 'bob.test';
7+
8+
const testAgents: Record<Handle, Agent> = {
9+
'alice.test': await createTestAgent('alice.test'),
10+
'bob.test': await createTestAgent('bob.test'),
11+
};
12+
13+
function createTestAgent(handle: Handle) {
14+
return createAgent(
15+
{
16+
identifier: handle,
17+
password: 'password',
18+
},
19+
{ service: inject('testPdsUrl') },
20+
);
21+
}
22+
23+
/**
24+
* Get Agent instance for testing accounts.
25+
* There are `@alice.test` and `@bob.test` now.
26+
* @param handle - handle name for test agent (without `@`)
27+
*/
28+
export async function getTestAgent(handle: Handle) {
29+
return testAgents[handle];
30+
}

packages/client/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"moduleResolution": "bundler",
1111
"paths": {
1212
"~/*": ["src/*"],
13+
"~~/*": ["*"],
1314
"@tsky/lexicons": ["../lexicons/index.ts"],
1415
},
1516
"resolveJsonModule": true,
@@ -31,7 +32,7 @@
3132
"verbatimModuleSyntax": true,
3233
"skipLibCheck": true
3334
},
34-
"include": ["./src/**/*", "./tests/**/*", "./test-utils/**/*"],
35+
"include": ["./src/**/*", "./globalSetup.ts", "./test-utils.ts"],
3536
"typedocOptions": {
3637
"out": "./docs",
3738
"theme": "default",

packages/client/vitest.config.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config';
22

33
export default defineConfig({
44
test: {
5+
globalSetup: 'globalSetup.ts',
56
coverage: {
67
provider: 'istanbul',
78
reporter: ['text', 'json-summary', 'json', 'html'],
@@ -11,6 +12,7 @@ export default defineConfig({
1112
resolve: {
1213
alias: {
1314
'~': '/src',
15+
'~~': '/',
1416
},
1517
},
1618
});

0 commit comments

Comments
 (0)