Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A connector is a small process that holds a key to a Marfa instance. It register
- [`readwise`](./connectors/readwise/README.md): sources and complete highlights from one Readwise account, read only, with resumable export checkpoints; with Reader turned on, also Reader documents, retained content, and supported two-way edits, one item per document.
- [`rss`](./connectors/rss/README.md): the entries of the feeds it is given, read only, and on request the pictures they point to, saved as files.
- [`google-calendar`](./connectors/google-calendar/README.md): a Google account's calendars and events, with series, changed occurrences and cancellations, and changes to events carried back.
- [`raindrop`](./connectors/raindrop/README.md): syncs bookmarks, collections and highlights with Raindrop.io in both directions and imports saved page copies and uploaded files.
- `connectors/<name>/plugin/`: the plugin each connector is published as, generated from the connector's own definition and read by `marfa plugins check` and the release. Its `plugin.json` names the connector's source, its kinds with the direction each moves, its settings and the edge types it writes; each kind has a type file and its guidance. `pnpm build`, then `pnpm connectors:generate` regenerates the JSON, and CI fails when it is out of date.
- [`scripts/`](./scripts): prepares the pinned Marfa server, holds the proof, which boots the pinned server and drives every connector against it, and holds the tests that guard the repository itself.

Expand Down
98 changes: 98 additions & 0 deletions connectors/raindrop/README.md

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions connectors/raindrop/live/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Raindrop live check

A check you run by hand against a real Raindrop.io account. It runs the
Raindrop connector, as built, against a throwaway local Marfa server and the
account, and prints a numbered list of statements, each `ok` or `FAIL` with
its evidence. It never runs in CI: no test glob, proof shard or workflow
picks it up. The unit tests of its fence, in `test/`, run with the other
tests against local servers and never reach Raindrop.

The account can hold real bookmarks. The check reads all of them, and changes
only the collections and bookmarks it makes itself, through a fence described
below.

## Before you start

From the repository root:

1. Install and build: `pnpm install --frozen-lockfile`, then `pnpm build`.
1. Fetch the pinned Marfa server: `scripts/monorepo.sh`.
1. Get a Raindrop test token for the account, from **Settings > Integrations**
in Raindrop.io. Make sure nothing in the account is tagged
`marfa-validation`; the check refuses to start if anything is.

## Run the check

Put the token in `RAINDROP_TEST_TOKEN` and run:

```sh
RAINDROP_TEST_TOKEN=<token> node --experimental-strip-types connectors/raindrop/live/check.ts
```

The token is never printed or logged, and never reaches Marfa or the
connector: the check removes `RAINDROP_TEST_TOKEN` from its environment as
soon as it reads it, so no process it starts inherits it. If your token is kept in Infisical, you can supply it the way
WithMarfa's workbench does:

```sh
aic-infisical-run --project-id ef9f1c46-c9ef-443d-836d-cb19c68d711f --env staging --path /local -- \
node --experimental-strip-types connectors/raindrop/live/check.ts
```

The check exits `0` when every statement holds, `1` when any fails, and `2`
when it refuses to start.

### Options

- `--self-test`: runs the whole check against the stand-in for Raindrop's API
in `scripts/proof/raindrop-stub.ts`, with no token, and adds writes to
objects the check did not make, to show that the fence refuses them and
fails the check. It exits `0` when that is so.
- `--clean`: deletes what an earlier run made and could not clean up.

### If a run stops

The check writes the ID of everything it makes to
`~/.cache/marfa-raindrop-live/made.json` as it goes. The file is outside the
system temp folder, which a supervisor can delete when a run ends. Clean-up
runs at the end of every run, after a failure, and after Control+C. If the
process is killed before clean-up finishes, run the check with `--clean`.
The check refuses to start while that file lists anything.

Clean-up also finds what the check made and lost the ID of: bookmarks tagged
`marfa-validation` under the check's address, and collections named for it.
Raindrop's search can miss a bookmark for minutes after it's made, so
clean-up lists the newest changed bookmarks in the check's collections,
Unsorted and Trash, and uses search only to add to what it finds. It never
takes anything the proxy found in the account before the check made
anything. The check's start guard looks for the tag the same way, and also
lists the newest changed bookmarks in the whole account.

## What it proves

1. A first import with `raindrop_read_only` on brings in every bookmark,
collection and highlight, compared with `/user/stats` and the listings,
and sends Raindrop no write.
1. With read-only off, on test collections only:
- Collections and bookmarks the check makes in Raindrop appear in Marfa.
- A bookmark, a collection and a highlight made in Marfa appear in
Raindrop.
- Title, note, tags and favorite edited on either side reach the other.
- Moves made on either side reach the other.
- A bookmark trashed in Marfa goes to Raindrop's Trash and isn't deleted,
and a restore brings it back.
- A create whose answer is lost ends with one bookmark.
- A `429` answer with `Retry-After` is waited out.
- A run killed partway and started again ends consistent.
- A collection trashed in Marfa is deleted and leaves its bookmarks in
Unsorted.
- Trashing more than 20 test bookmarks is held until
`raindrop_confirm_deletes` names the batch, then carried out.
- Raindrop's answers that the connector depends on: moving everything out
of an empty collection, and reading a deleted bookmark or collection.
1. Clean-up, always: every bookmark the check made is moved to Trash, deleted
again and answers `404`; every collection it made is deleted; Trash holds
none of them; and no `marfa-validation` tag is left.

## The fence

The connector runs with `raindrop_api_url` pointed at a local proxy the check
starts. Marfa holds a random placeholder as the connector's token; the proxy
accepts only that placeholder and sends the real token to
`https://api.raindrop.io/rest/v1/`, and nowhere else: it refuses a request
whose path, as sent or as resolved, isn't under `/rest/v1/`, and one whose
address, once built, leaves that host or path. It never follows a redirect;
it passes the redirect back. A request that bypasses the proxy can't
authenticate.

The proxy lets through these reads, each with only the query names listed,
since some of Raindrop's `GET` requests change things:

- `GET /user`, `/user/stats`, `/collections`, `/collections/childrens`,
`/collection/{id}`, `/tags`, and `/highlights` with `perpage` and `page`.
- `GET /raindrops/{id}` with `sort`, `perpage`, `page`, `search` and
`nested`.
- `GET /raindrop/{id}`, `/raindrop/{id}/cache` with `json`, and
`/raindrop/{id}/file`.

It lets through these writes, each without a query. A write with a body must
send it as `application/json` (parameters such as `charset` are allowed) and
as strict JSON: UTF-8 with no byte order mark and no key named twice in one
object. The proxy forwards the body as it read it, written out again, with
`Content-Type: application/json`.

- `POST /import/url/exists` with only a list of addresses, which looks up
bookmarks and changes nothing.
- `POST /raindrop` into no collection, Unsorted or a collection the check
made, and `POST /collection` at the top level or under a collection the
check made, neither naming an ID or its own `created` or `lastUpdate`.
- `PUT` and `DELETE` on a bookmark the check made. A `PUT` may move it only
to Unsorted, Trash or a collection the check made.
- `PUT /collection/{id}` on a collection the check made, kept under one it
made or at the top level.
- `DELETE /collection/{id}` on a collection the check made, when every
collection nested in it and every bookmark in them were made by the check.
- `PUT /raindrops/{id}` only for a collection the check made, never `0`, `-1`
or `-99`, without `nested`, moving only to Unsorted, Trash or a collection
the check made, with every bookmark in `ids` made by the check, or, with no
`ids`, only when every bookmark in that collection was made by the check.

It refuses everything else with `403` and records it as a violation, which
fails the check. A request without the placeholder is refused with `401` and
recorded the same way.

Before the check makes anything, the proxy reads every bookmark and
collection in the account, and notes the time from Raindrop's own clock. It
records the ID a create answers as the check's only when that ID wasn't in
the account before (in that first read, or in any answer the proxy passed on
before the create was sent) and its `created` time is after that first read.
An ID it refuses, or can't judge, is recorded as a violation and listed in
the made-IDs file without an ID, so clean-up never deletes it.
Loading