* refactor(crypto): remove circular dependency * refactor(crypto): expose compress/decompress as part of the DidKeyPlugin interface * fix(crypto): remove import from private file * refactor: isolate tsconfig * fix: remove unused bench file * chore(repo): remove unused deps * fix(ozone): properly list dependencies * fix(services): do lint js files * fix(services/pds): remove unused deps * chore(pds): remove bench * chore(dev-env): remove unused deps * chore(api): remove bench * remove unused babel.config.js files * fix: remove .ts extension from import * fix(pds): remove imports of src files * fix(tsconfig): properly list all projects * fix(dev-env): remove imports of src files * fix(bsky): remove direct import to crypto src * fix(api): remove imports to api internals * chore(build): prevent bundling of built output * chore(dev): add "dev" script to build in watch mode * chore(deps): move ts-node dependency where it is actually used * fix(deps): add dev-env as project dependency * fix(xrpc-server): properly type kexicon * fix(bsky): improve typings * fix(pds): fully type formatRecordEmbedInternal return value * fix(repo): remove imports from @ipld/car/api * feat(dev-env): re-export BskyIngester * fix: properly lint & type jest config & test files * fix(ci): test after build * fix(types): use NodeJS.Timeout instead of NodeJS.Timer * fix(bsky): make types exportable * fix(ozone): make types exportable * fix(xrpc-server): make types exportable * fix(xprc-server): make code compliant with "node" types * fix(xrpc-server): avoid accessing properties of unknown * chore(deps): update @types/node * feat(tsconfig): narrow down available types depending on the package's target environment * fix(pds): remove unused prop * fix(bsync): Database's migrator not always initialized * fix(dev-env): remove unreachable code * fix(xrpc-server): remove unused import * fix(xrpc-server): mark header property as abstract * fix(pds): initialize LeakyTxPlugin's txOver property * fix(bsky): initialize LeakyTxPlugin's txOver property * fix(bsky): remove unused migrator from DatabaseCoordinator * fix(bsky): Properly initialize LabelService's cache property * fix(ozone): Database's migrator not initialized * fix(ozone): initialize LeakyTxPlugin's txOver property * fix(crypto): ignore unused variable error * feat(tsconfig): use stricter rules * feat(tsconfig): enable useDefineForClassFields * feat(xrpc-server): add support for brotli incoming payload * fix(xrpc-server): properly parse & process content-encoding * fix(common:stream): always call cb in _transform * tidy/fix tests and service entrypoints * Revert "fix(xrpc-server): properly parse & process content-encoding" This reverts commit 2b1c66e153820d3e128fc839fcc1834d52a66686. * Revert "feat(xrpc-server): add support for brotli incoming payload" This reverts commit e710c21e6118214ddf215b0515e68cb87299a952. * remove special node env for tests (defaults to jest val of "test") * kill mute sync handler on disconnect * work around connect-es bug w/ request aborts * style(crypto): rename imports from uint8arrays * fix update package-lock * fix lint * force hbs files to be bundled as cjs * fix: use concurrently instead of npm-run-all npm-run-all seems not to be maintained anymore. Additionally, concurrently better forwards signals to child processes. * remove concurrently alltogether * ignore sqlite files in services/pds * fix verify * fix verify * tidy, fix verify * fix blob diversion test * build rework changeset --------- Co-authored-by: Devin Ivy <devinivy@gmail.com>
133 lines
4.2 KiB
TypeScript
133 lines
4.2 KiB
TypeScript
import AtpAgent from '@atproto/api'
|
|
import { cborDecode, cborEncode } from '@atproto/common'
|
|
import { DatabaseSchemaType } from '../../../src/data-plane/server/db/database-schema'
|
|
import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
|
|
import { PreparedWrite, sequencer } from '@atproto/pds'
|
|
import { CommitData } from '@atproto/repo'
|
|
import { ids } from '../../../src/lexicon/lexicons'
|
|
import { forSnapshot } from '../../_util'
|
|
|
|
type Database = TestNetwork['bsky']['db']
|
|
|
|
describe('sync', () => {
|
|
let network: TestNetwork
|
|
let pdsAgent: AtpAgent
|
|
let sc: SeedClient
|
|
|
|
beforeAll(async () => {
|
|
network = await TestNetwork.create({
|
|
dbPostgresSchema: 'bsky_subscription_repo',
|
|
})
|
|
pdsAgent = network.pds.getClient()
|
|
sc = network.getSeedClient()
|
|
await basicSeed(sc)
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await network.close()
|
|
})
|
|
|
|
it('indexes permit history being replayed.', async () => {
|
|
const { db } = network.bsky
|
|
|
|
// Generate some modifications and dupes
|
|
const { alice, bob, carol, dan } = sc.dids
|
|
await sc.follow(alice, bob)
|
|
await sc.follow(carol, alice)
|
|
await sc.follow(bob, alice)
|
|
await sc.follow(dan, bob)
|
|
await sc.like(dan, sc.posts[alice][1].ref) // Identical
|
|
await sc.like(alice, sc.posts[carol][0].ref) // Identical
|
|
await updateProfile(pdsAgent, alice, { displayName: 'ali!' })
|
|
await updateProfile(pdsAgent, bob, { displayName: 'robert!' })
|
|
|
|
await network.processAll()
|
|
|
|
// Table comparator
|
|
const getTableDump = async () => {
|
|
const [actor, post, profile, like, follow, dupes] = await Promise.all([
|
|
dumpTable(db, 'actor', ['did']),
|
|
dumpTable(db, 'post', ['uri']),
|
|
dumpTable(db, 'profile', ['uri']),
|
|
dumpTable(db, 'like', ['creator', 'subject']),
|
|
dumpTable(db, 'follow', ['creator', 'subjectDid']),
|
|
dumpTable(db, 'duplicate_record', ['uri']),
|
|
])
|
|
return { actor, post, profile, like, follow, dupes }
|
|
}
|
|
|
|
// Mark originals
|
|
const originalTableDump = await getTableDump()
|
|
|
|
// Reprocess repos via sync subscription, on top of existing indices
|
|
await network.bsky.sub.destroy()
|
|
// Hard reset of state
|
|
network.bsky.sub.cursor = 0
|
|
network.bsky.sub.seenSeq = null
|
|
// Boot streams back up
|
|
network.bsky.sub.run()
|
|
await network.processAll()
|
|
|
|
// Permissive of indexedAt times changing
|
|
expect(forSnapshot(await getTableDump())).toEqual(
|
|
forSnapshot(originalTableDump),
|
|
)
|
|
})
|
|
|
|
it('indexes actor when commit is unprocessable.', async () => {
|
|
// mock sequencing to create an unprocessable commit event
|
|
const sequenceCommitOrig = network.pds.ctx.sequencer.sequenceCommit
|
|
network.pds.ctx.sequencer.sequenceCommit = async function (
|
|
did: string,
|
|
commitData: CommitData,
|
|
writes: PreparedWrite[],
|
|
) {
|
|
const seqEvt = await sequencer.formatSeqCommit(did, commitData, writes)
|
|
const evt = cborDecode(seqEvt.event) as sequencer.CommitEvt
|
|
evt.blocks = new Uint8Array() // bad blocks
|
|
seqEvt.event = cborEncode(evt)
|
|
await network.pds.ctx.sequencer.sequenceEvt(seqEvt)
|
|
}
|
|
// create account and index the initial commit event
|
|
await sc.createAccount('jack', {
|
|
handle: 'jack.test',
|
|
email: 'jack@test.com',
|
|
password: 'password',
|
|
})
|
|
await network.processAll()
|
|
// confirm jack was indexed as an actor despite the bad event
|
|
const actors = await dumpTable(network.bsky.db, 'actor', ['did'])
|
|
expect(actors.map((a) => a.handle)).toContain('jack.test')
|
|
network.pds.ctx.sequencer.sequenceCommit = sequenceCommitOrig
|
|
})
|
|
|
|
async function updateProfile(
|
|
agent: AtpAgent,
|
|
did: string,
|
|
record: Record<string, unknown>,
|
|
) {
|
|
return await agent.api.com.atproto.repo.putRecord(
|
|
{
|
|
repo: did,
|
|
collection: ids.AppBskyActorProfile,
|
|
rkey: 'self',
|
|
record,
|
|
},
|
|
{ headers: sc.getHeaders(did), encoding: 'application/json' },
|
|
)
|
|
}
|
|
})
|
|
|
|
async function dumpTable<T extends keyof DatabaseSchemaType>(
|
|
db: Database,
|
|
tableName: T,
|
|
pkeys: (keyof DatabaseSchemaType[T] & string)[],
|
|
) {
|
|
const { ref } = db.db.dynamic
|
|
let builder = db.db.selectFrom(tableName).selectAll()
|
|
pkeys.forEach((key) => {
|
|
builder = builder.orderBy(ref(key))
|
|
})
|
|
return await builder.execute()
|
|
}
|