diff --git a/.github/workflows/deps-db-sync.yml b/.github/workflows/deps-db-sync.yml index e2c70d2a69..8d7fcf0330 100644 --- a/.github/workflows/deps-db-sync.yml +++ b/.github/workflows/deps-db-sync.yml @@ -6,25 +6,25 @@ on: push: branches: [master] paths: - - 'deps/db-sync/**' + - 'deps/workers/**' - '.github/workflows/deps-db-sync.yml' - - '!deps/db-sync/**.md' + - '!deps/workers/**.md' # Deps that logseq/db-sync depends on should trigger this workflow - 'deps/db/**' - 'deps/common/**' pull_request: branches: [master] paths: - - 'deps/db-sync/**' + - 'deps/workers/**' - '.github/workflows/deps-db-sync.yml' - - '!deps/db-sync/**.md' + - '!deps/workers/**.md' # Deps that logseq/db-sync depends on should trigger this workflow - 'deps/db/**' - 'deps/common/**' defaults: run: - working-directory: deps/db-sync + working-directory: deps/workers env: CLOJURE_VERSION: '1.11.1.1413' @@ -46,7 +46,7 @@ jobs: with: node-version: ${{ env.NODE_VERSION }} cache: 'yarn' - cache-dependency-path: deps/db-sync/yarn.lock + cache-dependency-path: deps/workers/yarn.lock - name: Set up Java uses: actions/setup-java@v4 diff --git a/.gitignore b/.gitignore index 2a6d1f091c..0ff1533dde 100644 --- a/.gitignore +++ b/.gitignore @@ -69,9 +69,9 @@ deps/shui/.clj-kondo deps/publish/worker/.wrangler deps/publish/worker/dist deps/publish/worker/.env* -deps/db-sync/worker/.wrangler -deps/db-sync/worker/dist -deps/db-sync/worker/.env* +deps/workers/worker/.wrangler +deps/workers/worker/dist +deps/workers/worker/.env* tx-log* @@ -79,5 +79,5 @@ clj-e2e/.wally clj-e2e/e2e-dump .dir-locals.el .projectile -deps/db-sync/data +deps/workers/data /packages/ui/@/lib/streamdown-bundle.js diff --git a/bb.edn b/bb.edn index 23aa46d309..e72bbf8020 100644 --- a/bb.edn +++ b/bb.edn @@ -172,12 +172,12 @@ dev:db-sync-test {:doc "Run db-sync server unit tests" - :task (do (shell {:dir "deps/db-sync"} "clojure -M:cljs compile db-sync-test") - (shell {:dir "deps/db-sync"} "node worker/dist/worker-test.js"))} + :task (do (shell {:dir "deps/workers"} "clojure -M:cljs compile db-sync-test") + (shell {:dir "deps/workers"} "node worker/dist/worker-test.js"))} dev:db-sync-start {:doc "Start db-sync local server + client watch processes in foreground" - :task logseq.tasks.dev.db-sync/start} + :task logseq.tasks.dev.sync/start} dev:gen-malli-kondo-config logseq.tasks.dev/gen-malli-kondo-config diff --git a/deps.edn b/deps.edn index 9bfc69417c..f71a40a479 100644 --- a/deps.edn +++ b/deps.edn @@ -37,7 +37,7 @@ logseq/common {:local/root "deps/common"} logseq/graph-parser {:local/root "deps/graph-parser"} logseq/outliner {:local/root "deps/outliner"} - logseq/db-sync {:local/root "deps/db-sync"} + logseq/db-sync {:local/root "deps/workers"} logseq/publishing {:local/root "deps/publishing"} logseq/cli {:local/root "deps/cli"} logseq/shui {:local/root "deps/shui"} diff --git a/deps/db-sync/.carve/ignore b/deps/db-sync/.carve/ignore deleted file mode 100644 index dbc8e2ddb8..0000000000 --- a/deps/db-sync/.carve/ignore +++ /dev/null @@ -1,24 +0,0 @@ -;; API -logseq.db-sync.cycle/fix-cycle! -;; API -logseq.db-sync.node.entry/main -;; API -logseq.db-sync.order/fix-duplicate-orders! -;; TODO: is this ns needed? -logseq.db-sync.platform.cloudflare/response -logseq.db-sync.platform.cloudflare/request -logseq.db-sync.platform.cloudflare/request-url -;; testing -logseq.db-sync.protocol/tx->transit -;; debugging -logseq.db-sync.protocol/datoms->wire -;; debugging -logseq.db-sync.protocol/datoms->wire -;; debugging -logseq.db-sync.sentry.node/capture-exception! -;; Used? -logseq.db-sync.snapshot/framed-length -;; API -logseq.db-sync.worker/worker -;; debugging -logseq.db-sync.worker.timing/summary \ No newline at end of file diff --git a/deps/db-sync/.clj-condo/config.edn b/deps/db-sync/.clj-condo/config.edn deleted file mode 100644 index 6ad55084c2..0000000000 --- a/deps/db-sync/.clj-condo/config.edn +++ /dev/null @@ -1,28 +0,0 @@ -{:linters - {:aliased-namespace-symbol {:level :warning} - :namespace-name-mismatch {:level :warning} - :used-underscored-binding {:level :warning} - :shadowed-var {:level :warning - :exclude [meta name key keys uuid type]} - - :consistent-alias - {:aliases {clojure.pprint pprint - clojure.string string - datascript.core d - datascript.transit dt - logseq.db-sync.common common - logseq.db-sync.config config - logseq.db-sync.node.routes node-routes - logseq.db-sync.platform.core platform - logseq.db-sync.protocol protocol - logseq.db-sync.storage storage - logseq.db-sync.worker.auth auth - logseq.db-sync.worker.handler.sync sync-handler - logseq.db-sync.worker.handler.ws ws-handler - logseq.db-sync.worker.http http - logseq.db-sync.worker.routes.index routes - logseq.db-sync.worker.ws ws}}} - :lint-as {promesa.core/let clojure.core/let - shadow.cljs.modern/defclass clj-kondo.lint-as/def-catch-all} - :skip-comments true - :output {:progress true}} \ No newline at end of file diff --git a/deps/db-sync/src/logseq/db_sync/platform/cloudflare.cljs b/deps/db-sync/src/logseq/db_sync/platform/cloudflare.cljs deleted file mode 100644 index fe9616b185..0000000000 --- a/deps/db-sync/src/logseq/db_sync/platform/cloudflare.cljs +++ /dev/null @@ -1,6 +0,0 @@ -(ns logseq.db-sync.platform.cloudflare - (:require [logseq.db-sync.platform.core :as core])) - -(def response core/response) -(def request core/request) -(def request-url core/request-url) diff --git a/deps/db-sync/test/logseq/db_sync/node_server_test.cljs b/deps/db-sync/test/logseq/db_sync/node_server_test.cljs deleted file mode 100644 index 97c165391a..0000000000 --- a/deps/db-sync/test/logseq/db_sync/node_server_test.cljs +++ /dev/null @@ -1,119 +0,0 @@ -(ns logseq.db-sync.node-server-test - (:require [cljs.test :refer [async deftest is]] - [logseq.db-sync.node.server :as node-server] - [logseq.db-sync.worker.auth :as auth] - [promesa.core :as p])) - -(defn- fetch-with-timeout [url timeout-ms] - (let [timeout-sentinel ::timeout] - {:sentinel timeout-sentinel - :promise (js/Promise. - (fn [resolve reject] - (let [controller (js/AbortController.) - timeout-id (js/setTimeout - (fn [] - (.abort controller)) - timeout-ms)] - (-> (js/fetch url #js {:method "GET" - :headers #js {"authorization" "Bearer test.token.sig"} - :signal (.-signal controller)}) - (.then (fn [response] - (js/clearTimeout timeout-id) - (resolve response))) - (.catch (fn [error] - (js/clearTimeout timeout-id) - (if (= "AbortError" (.-name error)) - (resolve timeout-sentinel) - (reject error))))))))})) - -(deftest node-server-returns-500-when-auth-claims-rejects-test - (async done - (let [stop-server! (atom nil) - test-url (atom nil)] - (-> (p/with-redefs [auth/auth-claims - (fn [_request _env] - (p/rejected (ex-info "jwks" {})))] - (p/let [{:keys [base-url stop!]} (node-server/start! {:port 0 - :data-dir (str "tmp/db-sync-node-server-test/" (random-uuid))}) - _ (reset! stop-server! stop!) - _ (reset! test-url (str base-url "/graphs")) - {:keys [promise sentinel]} (fetch-with-timeout @test-url 1200) - response promise] - (if (identical? response sentinel) - (is false "request timed out") - (p/let [body (.json response)] - (is (= 500 (.-status response))) - (is (= "server error" (aget body "error"))))))) - (p/then - (fn [] - (if-let [stop! @stop-server!] - (-> (stop!) - (p/then (fn [] (done))) - (p/catch (fn [error] - (is false (str error)) - (done)))) - (done)))) - (p/catch - (fn [error] - (if-let [stop! @stop-server!] - (-> (stop!) - (p/then (fn [] - (is false (str error)) - (done))) - (p/catch (fn [stop-error] - (is false (str error)) - (is false (str stop-error)) - (done)))) - (do - (is false (str error)) - (done))))))))) - -(deftest node-server-logs-request-failed-marker-when-auth-claims-rejects-test - (async done - (let [stop-server! (atom nil) - original-console-error (.-error js/console) - logged-errors (atom [])] - (aset js/console - "error" - (fn [& args] - (swap! logged-errors conj args))) - (-> (p/with-redefs [auth/auth-claims - (fn [_request _env] - (p/rejected (ex-info "jwks" {})))] - (p/let [{:keys [base-url stop!]} (node-server/start! {:port 0 - :data-dir (str "tmp/db-sync-node-server-log-test/" (random-uuid))}) - _ (reset! stop-server! stop!) - _ (reset! logged-errors []) - {:keys [promise sentinel]} (fetch-with-timeout (str base-url "/graphs") 1200) - response promise] - (if (identical? response sentinel) - (is false "request timed out") - (do - (is (= 500 (.-status response))) - (is (some #(= ":db-sync/node-request-failed" (first %)) - @logged-errors)))))) - (p/then - (fn [] - (aset js/console "error" original-console-error) - (if-let [stop! @stop-server!] - (-> (stop!) - (p/then (fn [] (done))) - (p/catch (fn [error] - (is false (str error)) - (done)))) - (done)))) - (p/catch - (fn [error] - (aset js/console "error" original-console-error) - (if-let [stop! @stop-server!] - (-> (stop!) - (p/then (fn [] - (is false (str error)) - (done))) - (p/catch (fn [stop-error] - (is false (str error)) - (is false (str stop-error)) - (done)))) - (do - (is false (str error)) - (done))))))))) diff --git a/deps/db-sync/test/logseq/db_sync/test_runner.cljs b/deps/db-sync/test/logseq/db_sync/test_runner.cljs deleted file mode 100644 index 526ea64970..0000000000 --- a/deps/db-sync/test/logseq/db_sync/test_runner.cljs +++ /dev/null @@ -1,38 +0,0 @@ -(ns logseq.db-sync.test-runner - (:require [cljs.test :as ct] - [logseq.db-sync.agent-do-test] - [logseq.db-sync.agent-request-test] - [logseq.db-sync.agent-runtime-provider-test] - [logseq.db-sync.agent-source-control-test] - [logseq.db-sync.common-test] - [logseq.db-sync.index-test] - [logseq.db-sync.node-adapter-test] - [logseq.db-sync.node-config-test] - [logseq.db-sync.node-server-test] - [logseq.db-sync.normalize-test] - [logseq.db-sync.platform-test] - [logseq.db-sync.worker-agents-dispatch-test] - [logseq.db-sync.worker-auth-test] - [logseq.db-sync.worker-handler-assets-test] - [logseq.db-sync.worker-handler-index-test] - [logseq.db-sync.worker-handler-sync-test] - [logseq.db-sync.worker-handler-ws-test] - [logseq.db-sync.worker-routes-test] - [shadow.test :as st] - [shadow.test.env :as env])) - -(derive ::node ::ct/default) - -(defmethod ct/report [::node :end-run-tests] [m] - (if (ct/successful? m) - (js/process.exit 0) - (js/process.exit 1))) - -(defn ^:dev/after-load reset-test-data! [] - (-> (env/get-test-data) - (env/reset-test-data!))) - -(defn main [& _args] - (reset-test-data!) - (let [test-env (ct/empty-env ::node)] - (st/run-all-tests test-env nil))) diff --git a/deps/workers/.carve/ignore b/deps/workers/.carve/ignore new file mode 100644 index 0000000000..505b2cc46d --- /dev/null +++ b/deps/workers/.carve/ignore @@ -0,0 +1,24 @@ +;; API +logseq.sync.cycle/fix-cycle! +;; API +logseq.sync.node.entry/main +;; API +logseq.sync.order/fix-duplicate-orders! +;; TODO: is this ns needed? +logseq.sync.platform.cloudflare/response +logseq.sync.platform.cloudflare/request +logseq.sync.platform.cloudflare/request-url +;; testing +logseq.sync.protocol/tx->transit +;; debugging +logseq.sync.protocol/datoms->wire +;; debugging +logseq.sync.protocol/datoms->wire +;; debugging +logseq.sync.sentry.node/capture-exception! +;; Used? +logseq.sync.snapshot/framed-length +;; API +logseq.sync.worker/worker +;; debugging +logseq.sync.worker.timing/summary \ No newline at end of file diff --git a/deps/workers/.clj-condo/config.edn b/deps/workers/.clj-condo/config.edn new file mode 100644 index 0000000000..aa853058f6 --- /dev/null +++ b/deps/workers/.clj-condo/config.edn @@ -0,0 +1,28 @@ +{:linters + {:aliased-namespace-symbol {:level :warning} + :namespace-name-mismatch {:level :warning} + :used-underscored-binding {:level :warning} + :shadowed-var {:level :warning + :exclude [meta name key keys uuid type]} + + :consistent-alias + {:aliases {clojure.pprint pprint + clojure.string string + datascript.core d + datascript.transit dt + logseq.sync.common common + logseq.sync.config config + logseq.sync.node.routes node-routes + logseq.sync.platform.core platform + logseq.sync.protocol protocol + logseq.sync.storage storage + logseq.sync.worker.auth auth + logseq.sync.worker.handler.sync sync-handler + logseq.sync.worker.handler.ws ws-handler + logseq.sync.worker.http http + logseq.sync.worker.routes.index routes + logseq.sync.worker.ws ws}}} + :lint-as {promesa.core/let clojure.core/let + shadow.cljs.modern/defclass clj-kondo.lint-as/def-catch-all} + :skip-comments true + :output {:progress true}} \ No newline at end of file diff --git a/deps/db-sync/README.md b/deps/workers/README.md similarity index 97% rename from deps/db-sync/README.md rename to deps/workers/README.md index f9a1c6d1cd..2e3b186b39 100644 --- a/deps/db-sync/README.md +++ b/deps/workers/README.md @@ -1,4 +1,4 @@ -# Logseq DB Sync (deps/db-sync) +# Logseq DB Sync (deps/workers) This package contains db-sync and agents worker code plus tests used by Logseq. It includes separate Cloudflare worker entrypoints and a Node.js adapter for self-hosting. @@ -14,22 +14,22 @@ It includes separate Cloudflare worker entrypoints and a Node.js adapter for sel DB sync worker (`/sync/*`, `/graphs*`, `/e2ee*`, `/assets/*`): ```bash -cd deps/db-sync +cd deps/workers yarn watch # open another terminal -cd deps/db-sync/worker +cd deps/workers/worker wrangler dev ``` Agents worker (`/sessions*`): ```bash -cd deps/db-sync +cd deps/workers yarn watch:agents # open another terminal -cd deps/db-sync/worker +cd deps/workers/worker wrangler dev -c wrangler.agents.toml ``` @@ -52,7 +52,7 @@ The worker no longer initializes schema at request time. Apply the D1 schema via migrations during deployment/CI. ```bash -cd deps/db-sync/worker +cd deps/workers/worker wrangler d1 migrations apply logseq-sync-graph-meta-staging --env staging wrangler d1 migrations apply logseq-sync-graphs-prod --env prod ``` @@ -64,7 +64,7 @@ For local development, run `wrangler d1 migrations apply DB --local`. Build the adapter: ```bash -cd deps/db-sync +cd deps/workers npm run build:node-adapter ``` @@ -83,7 +83,7 @@ node worker/dist/node-adapter.js Run db-sync tests (includes Node adapter tests): ```bash -cd deps/db-sync +cd deps/workers npm run test:node-adapter ``` @@ -92,7 +92,7 @@ npm run test:node-adapter Use the local sandbox-agent repo at `~/Codes/projects/sandbox-agent`: ```bash -cd deps/db-sync +cd deps/workers ./scripts/start-local-sandbox-agent.sh ``` @@ -111,7 +111,7 @@ SANDBOX_AGENT_TOKEN=... Smoke test a Codex-backed session: ```bash -cd deps/db-sync +cd deps/workers BASE_URL=http://127.0.0.1:8787 ./scripts/start-weather-session.sh ``` diff --git a/deps/db-sync/bb.edn b/deps/workers/bb.edn similarity index 100% rename from deps/db-sync/bb.edn rename to deps/workers/bb.edn diff --git a/deps/db-sync/deps.edn b/deps/workers/deps.edn similarity index 100% rename from deps/db-sync/deps.edn rename to deps/workers/deps.edn diff --git a/deps/db-sync/docs/adr/0002-agent-service-document-driven-development.md b/deps/workers/docs/adr/0002-agent-service-document-driven-development.md similarity index 100% rename from deps/db-sync/docs/adr/0002-agent-service-document-driven-development.md rename to deps/workers/docs/adr/0002-agent-service-document-driven-development.md diff --git a/deps/db-sync/docs/milestones/agents/00-index.md b/deps/workers/docs/milestones/agents/00-index.md similarity index 100% rename from deps/db-sync/docs/milestones/agents/00-index.md rename to deps/workers/docs/milestones/agents/00-index.md diff --git a/deps/db-sync/docs/milestones/agents/01-m1-architecture-api-shape.md b/deps/workers/docs/milestones/agents/01-m1-architecture-api-shape.md similarity index 100% rename from deps/db-sync/docs/milestones/agents/01-m1-architecture-api-shape.md rename to deps/workers/docs/milestones/agents/01-m1-architecture-api-shape.md diff --git a/deps/db-sync/docs/milestones/agents/02-m2-control-plane-prototype.md b/deps/workers/docs/milestones/agents/02-m2-control-plane-prototype.md similarity index 100% rename from deps/db-sync/docs/milestones/agents/02-m2-control-plane-prototype.md rename to deps/workers/docs/milestones/agents/02-m2-control-plane-prototype.md diff --git a/deps/db-sync/docs/milestones/agents/03-m3-sandbox-agent-integration.md b/deps/workers/docs/milestones/agents/03-m3-sandbox-agent-integration.md similarity index 100% rename from deps/db-sync/docs/milestones/agents/03-m3-sandbox-agent-integration.md rename to deps/workers/docs/milestones/agents/03-m3-sandbox-agent-integration.md diff --git a/deps/db-sync/docs/milestones/agents/04-m4-operational-readiness.md b/deps/workers/docs/milestones/agents/04-m4-operational-readiness.md similarity index 100% rename from deps/db-sync/docs/milestones/agents/04-m4-operational-readiness.md rename to deps/workers/docs/milestones/agents/04-m4-operational-readiness.md diff --git a/deps/db-sync/docs/milestones/agents/05-m5-project-task-model.md b/deps/workers/docs/milestones/agents/05-m5-project-task-model.md similarity index 100% rename from deps/db-sync/docs/milestones/agents/05-m5-project-task-model.md rename to deps/workers/docs/milestones/agents/05-m5-project-task-model.md diff --git a/deps/db-sync/docs/milestones/agents/06-m6-sprites-default-runtime.md b/deps/workers/docs/milestones/agents/06-m6-sprites-default-runtime.md similarity index 86% rename from deps/db-sync/docs/milestones/agents/06-m6-sprites-default-runtime.md rename to deps/workers/docs/milestones/agents/06-m6-sprites-default-runtime.md index 36e21cdca8..34552c1942 100644 --- a/deps/db-sync/docs/milestones/agents/06-m6-sprites-default-runtime.md +++ b/deps/workers/docs/milestones/agents/06-m6-sprites-default-runtime.md @@ -27,7 +27,7 @@ Run task sessions on Sprites by default so every `#Task` can provision an isolat ## Workstreams ### WS1: Provider Implementation -- Add `SpritesProvider` in `src/logseq/db_sync/worker/agent/runtime_provider.cljs`. +- Add `SpritesProvider` in `src/logseq/agents/runtime_provider.cljs`. - Implement: - `object [headers] diff --git a/deps/db-sync/src/logseq/db_sync/protocol.cljs b/deps/workers/src/logseq/sync/protocol.cljs similarity index 88% rename from deps/db-sync/src/logseq/db_sync/protocol.cljs rename to deps/workers/src/logseq/sync/protocol.cljs index 314765303c..0b4a27d264 100644 --- a/deps/db-sync/src/logseq/db_sync/protocol.cljs +++ b/deps/workers/src/logseq/sync/protocol.cljs @@ -1,5 +1,5 @@ -(ns logseq.db-sync.protocol - (:require [logseq.db-sync.common :as common])) +(ns logseq.sync.protocol + (:require [logseq.sync.common :as common])) (defn parse-message [raw] (try diff --git a/deps/db-sync/src/logseq/db_sync/sentry.cljs b/deps/workers/src/logseq/sync/sentry.cljs similarity index 96% rename from deps/db-sync/src/logseq/db_sync/sentry.cljs rename to deps/workers/src/logseq/sync/sentry.cljs index 21dde3ac45..1ceed85b0b 100644 --- a/deps/db-sync/src/logseq/db_sync/sentry.cljs +++ b/deps/workers/src/logseq/sync/sentry.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.sentry) +(ns logseq.sync.sentry) (defn- not-blank [v] (when (and (string? v) (seq v)) v)) diff --git a/deps/db-sync/src/logseq/db_sync/sentry/node.cljs b/deps/workers/src/logseq/sync/sentry/node.cljs similarity index 72% rename from deps/db-sync/src/logseq/db_sync/sentry/node.cljs rename to deps/workers/src/logseq/sync/sentry/node.cljs index 608a0f6a35..4b9985a0d1 100644 --- a/deps/db-sync/src/logseq/db_sync/sentry/node.cljs +++ b/deps/workers/src/logseq/sync/sentry/node.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.sentry.node +(ns logseq.sync.sentry.node (:require ["@sentry/node" :as sentry] - [logseq.db-sync.sentry :as sentry-config])) + [logseq.sync.sentry :as sentry-config])) (defn init! [] (when-let [opts (sentry-config/options-from-env (.-env js/process))] diff --git a/deps/db-sync/src/logseq/db_sync/sentry/worker.cljs b/deps/workers/src/logseq/sync/sentry/worker.cljs similarity index 76% rename from deps/db-sync/src/logseq/db_sync/sentry/worker.cljs rename to deps/workers/src/logseq/sync/sentry/worker.cljs index b27605ee7d..8143b9ab5c 100644 --- a/deps/db-sync/src/logseq/db_sync/sentry/worker.cljs +++ b/deps/workers/src/logseq/sync/sentry/worker.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.sentry.worker +(ns logseq.sync.sentry.worker (:require ["@sentry/cloudflare" :as sentry] - [logseq.db-sync.sentry :as sentry-config])) + [logseq.sync.sentry :as sentry-config])) (defn wrap-handler [handler] (sentry/withSentry (fn [^js env] diff --git a/deps/db-sync/src/logseq/db_sync/snapshot.cljs b/deps/workers/src/logseq/sync/snapshot.cljs similarity index 98% rename from deps/db-sync/src/logseq/db_sync/snapshot.cljs rename to deps/workers/src/logseq/sync/snapshot.cljs index 74ab9b06a9..1fb1022da1 100644 --- a/deps/db-sync/src/logseq/db_sync/snapshot.cljs +++ b/deps/workers/src/logseq/sync/snapshot.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.snapshot +(ns logseq.sync.snapshot (:require [cognitect.transit :as transit])) (def ^:private transit-w (transit/writer :json)) diff --git a/deps/db-sync/src/logseq/db_sync/storage.cljs b/deps/workers/src/logseq/sync/storage.cljs similarity index 98% rename from deps/db-sync/src/logseq/db_sync/storage.cljs rename to deps/workers/src/logseq/sync/storage.cljs index 51de51072a..c2ff411604 100644 --- a/deps/db-sync/src/logseq/db_sync/storage.cljs +++ b/deps/workers/src/logseq/sync/storage.cljs @@ -1,9 +1,9 @@ -(ns logseq.db-sync.storage +(ns logseq.sync.storage (:require [cljs-bean.core :as bean] [clojure.string :as string] [datascript.core :as d] [datascript.storage :refer [IStorage]] - [logseq.db-sync.common :as common] + [logseq.sync.common :as common] [logseq.db.common.normalize :as db-normalize] [logseq.db.common.sqlite :as common-sqlite] [logseq.db.frontend.schema :as db-schema])) diff --git a/deps/db-sync/src/logseq/db_sync/worker.cljs b/deps/workers/src/logseq/sync/worker.cljs similarity index 86% rename from deps/db-sync/src/logseq/db_sync/worker.cljs rename to deps/workers/src/logseq/sync/worker.cljs index d1b51774e5..2b3a6c7361 100644 --- a/deps/db-sync/src/logseq/db_sync/worker.cljs +++ b/deps/workers/src/logseq/sync/worker.cljs @@ -1,16 +1,16 @@ -(ns logseq.db-sync.worker +(ns logseq.sync.worker ;; Turn off false defclass errors {:clj-kondo/config {:linters {:unresolved-symbol {:level :off}}}} (:require ["cloudflare:workers" :refer [DurableObject]] [lambdaisland.glogi :as log] - [logseq.db-sync.common :as common] - [logseq.db-sync.logging :as logging] - [logseq.db-sync.sentry.worker :as sentry] - [logseq.db-sync.worker.dispatch :as dispatch] - [logseq.db-sync.worker.handler.sync :as sync-handler] - [logseq.db-sync.worker.handler.ws :as ws-handler] - [logseq.db-sync.worker.presence :as presence] - [logseq.db-sync.worker.ws :as ws] + [logseq.sync.common :as common] + [logseq.sync.logging :as logging] + [logseq.sync.sentry.worker :as sentry] + [logseq.sync.worker.dispatch :as dispatch] + [logseq.sync.worker.handler.sync :as sync-handler] + [logseq.sync.worker.handler.ws :as ws-handler] + [logseq.sync.worker.presence :as presence] + [logseq.sync.worker.ws :as ws] [promesa.core :as p] [shadow.cljs.modern :refer (defclass)])) diff --git a/deps/db-sync/src/logseq/db_sync/worker/auth.cljs b/deps/workers/src/logseq/sync/worker/auth.cljs similarity index 98% rename from deps/db-sync/src/logseq/db_sync/worker/auth.cljs rename to deps/workers/src/logseq/sync/worker/auth.cljs index 66bff29f1c..b9eb5224a5 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/auth.cljs +++ b/deps/workers/src/logseq/sync/worker/auth.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.worker.auth +(ns logseq.sync.worker.auth (:require [clojure.string :as string] [logseq.common.authorization :as authorization] [promesa.core :as p])) diff --git a/deps/db-sync/src/logseq/db_sync/worker/coerce.cljs b/deps/workers/src/logseq/sync/worker/coerce.cljs similarity index 92% rename from deps/db-sync/src/logseq/db_sync/worker/coerce.cljs rename to deps/workers/src/logseq/sync/worker/coerce.cljs index 27ee8002b5..d3c9bcfd32 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/coerce.cljs +++ b/deps/workers/src/logseq/sync/worker/coerce.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.worker.coerce +(ns logseq.sync.worker.coerce (:require [lambdaisland.glogi :as log])) (def invalid-coerce ::invalid-coerce) diff --git a/deps/db-sync/src/logseq/db_sync/worker/dispatch.cljs b/deps/workers/src/logseq/sync/worker/dispatch.cljs similarity index 93% rename from deps/db-sync/src/logseq/db_sync/worker/dispatch.cljs rename to deps/workers/src/logseq/sync/worker/dispatch.cljs index 67bbd2f368..f9533da2a6 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/dispatch.cljs +++ b/deps/workers/src/logseq/sync/worker/dispatch.cljs @@ -1,10 +1,10 @@ -(ns logseq.db-sync.worker.dispatch +(ns logseq.sync.worker.dispatch (:require [clojure.string :as string] - [logseq.db-sync.common :as common] - [logseq.db-sync.platform.core :as platform] - [logseq.db-sync.worker.handler.assets :as assets-handler] - [logseq.db-sync.worker.handler.index :as index-handler] - [logseq.db-sync.worker.http :as http] + [logseq.sync.common :as common] + [logseq.sync.platform.core :as platform] + [logseq.sync.worker.handler.assets :as assets-handler] + [logseq.sync.worker.handler.index :as index-handler] + [logseq.sync.worker.http :as http] [promesa.core :as p])) (def ^:private agents-local-forward-max-retries 300) diff --git a/deps/db-sync/src/logseq/db_sync/worker/handler/assets.cljs b/deps/workers/src/logseq/sync/worker/handler/assets.cljs similarity index 97% rename from deps/db-sync/src/logseq/db_sync/worker/handler/assets.cljs rename to deps/workers/src/logseq/sync/worker/handler/assets.cljs index 47d280e16c..95dd4ab859 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/handler/assets.cljs +++ b/deps/workers/src/logseq/sync/worker/handler/assets.cljs @@ -1,8 +1,8 @@ -(ns logseq.db-sync.worker.handler.assets +(ns logseq.sync.worker.handler.assets (:require [cljs-bean.core :as bean] [clojure.string :as string] - [logseq.db-sync.common :as common :refer [cors-headers]] - [logseq.db-sync.worker.http :as http])) + [logseq.sync.common :as common :refer [cors-headers]] + [logseq.sync.worker.http :as http])) (def ^:private max-asset-size (* 100 1024 1024)) diff --git a/deps/db-sync/src/logseq/db_sync/worker/handler/index.cljs b/deps/workers/src/logseq/sync/worker/handler/index.cljs similarity index 98% rename from deps/db-sync/src/logseq/db_sync/worker/handler/index.cljs rename to deps/workers/src/logseq/sync/worker/handler/index.cljs index f93593e1ad..1949cf7574 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/handler/index.cljs +++ b/deps/workers/src/logseq/sync/worker/handler/index.cljs @@ -1,10 +1,10 @@ -(ns logseq.db-sync.worker.handler.index +(ns logseq.sync.worker.handler.index (:require [lambdaisland.glogi :as log] - [logseq.db-sync.common :as common] - [logseq.db-sync.index :as index] - [logseq.db-sync.worker.auth :as auth] - [logseq.db-sync.worker.http :as http] - [logseq.db-sync.worker.routes.index :as routes] + [logseq.sync.common :as common] + [logseq.sync.index :as index] + [logseq.sync.worker.auth :as auth] + [logseq.sync.worker.http :as http] + [logseq.sync.worker.routes.index :as routes] [promesa.core :as p])) (defn- index-db [^js self] diff --git a/deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs b/deps/workers/src/logseq/sync/worker/handler/sync.cljs similarity index 97% rename from deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs rename to deps/workers/src/logseq/sync/worker/handler/sync.cljs index 29f60b860b..094387ec26 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs +++ b/deps/workers/src/logseq/sync/worker/handler/sync.cljs @@ -1,15 +1,15 @@ -(ns logseq.db-sync.worker.handler.sync +(ns logseq.sync.worker.handler.sync (:require [clojure.string :as string] [lambdaisland.glogi :as log] [logseq.db :as ldb] - [logseq.db-sync.batch :as batch] - [logseq.db-sync.common :as common] - [logseq.db-sync.protocol :as protocol] - [logseq.db-sync.snapshot :as snapshot] - [logseq.db-sync.storage :as storage] - [logseq.db-sync.worker.http :as http] - [logseq.db-sync.worker.routes.sync :as sync-routes] - [logseq.db-sync.worker.ws :as ws] + [logseq.sync.batch :as batch] + [logseq.sync.common :as common] + [logseq.sync.protocol :as protocol] + [logseq.sync.snapshot :as snapshot] + [logseq.sync.storage :as storage] + [logseq.sync.worker.http :as http] + [logseq.sync.worker.routes.sync :as sync-routes] + [logseq.sync.worker.ws :as ws] [promesa.core :as p])) (def ^:private snapshot-download-batch-size 5000) diff --git a/deps/db-sync/src/logseq/db_sync/worker/handler/ws.cljs b/deps/workers/src/logseq/sync/worker/handler/ws.cljs similarity index 87% rename from deps/db-sync/src/logseq/db_sync/worker/handler/ws.cljs rename to deps/workers/src/logseq/sync/worker/handler/ws.cljs index 0081d961a7..7b10424514 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/handler/ws.cljs +++ b/deps/workers/src/logseq/sync/worker/handler/ws.cljs @@ -1,9 +1,9 @@ -(ns logseq.db-sync.worker.handler.ws - (:require [logseq.db-sync.protocol :as protocol] - [logseq.db-sync.worker.auth :as auth] - [logseq.db-sync.worker.handler.sync :as sync-handler] - [logseq.db-sync.worker.presence :as presence] - [logseq.db-sync.worker.ws :as ws])) +(ns logseq.sync.worker.handler.ws + (:require [logseq.sync.protocol :as protocol] + [logseq.sync.worker.auth :as auth] + [logseq.sync.worker.handler.sync :as sync-handler] + [logseq.sync.worker.presence :as presence] + [logseq.sync.worker.ws :as ws])) (defn handle-ws-message! [^js self ^js ws raw] (let [message (-> raw protocol/parse-message ws/coerce-ws-client-message)] diff --git a/deps/db-sync/src/logseq/db_sync/worker/http.cljs b/deps/workers/src/logseq/sync/worker/http.cljs similarity index 87% rename from deps/db-sync/src/logseq/db_sync/worker/http.cljs rename to deps/workers/src/logseq/sync/worker/http.cljs index 910222b88b..1d72fbaab7 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/http.cljs +++ b/deps/workers/src/logseq/sync/worker/http.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.worker.http - (:require [logseq.db-sync.common :as common] - [logseq.db-sync.malli-schema :as db-sync-schema] - [logseq.db-sync.worker.coerce :as coerce])) +(ns logseq.sync.worker.http + (:require [logseq.sync.common :as common] + [logseq.sync.malli-schema :as db-sync-schema] + [logseq.sync.worker.coerce :as coerce])) (defn coerce-http-request [schema-key body] (if-let [coercer (get db-sync-schema/http-request-coercers schema-key)] diff --git a/deps/db-sync/src/logseq/db_sync/worker/presence.cljs b/deps/workers/src/logseq/sync/worker/presence.cljs similarity index 95% rename from deps/db-sync/src/logseq/db_sync/worker/presence.cljs rename to deps/workers/src/logseq/sync/worker/presence.cljs index 379fa6fa16..d7e0a2efe7 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/presence.cljs +++ b/deps/workers/src/logseq/sync/worker/presence.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.worker.presence +(ns logseq.sync.worker.presence (:require [clojure.string :as string] - [logseq.db-sync.worker.ws :as ws])) + [logseq.sync.worker.ws :as ws])) (defn claims->user [claims] diff --git a/deps/db-sync/src/logseq/db_sync/worker/routes/index.cljs b/deps/workers/src/logseq/sync/worker/routes/index.cljs similarity index 60% rename from deps/db-sync/src/logseq/db_sync/worker/routes/index.cljs rename to deps/workers/src/logseq/sync/worker/routes/index.cljs index 340ab249b6..e52ffaed9b 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/routes/index.cljs +++ b/deps/workers/src/logseq/sync/worker/routes/index.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.worker.routes.index +(ns logseq.sync.worker.routes.index (:require [reitit.core :as r])) (def ^:private route-data @@ -20,21 +20,7 @@ ["/graphs/:graph-id" ["/aes-key" {:methods {"GET" :e2ee/graph-aes-key-get "POST" :e2ee/graph-aes-key-post}}] - ["/grant-access" {:methods {"POST" :e2ee/grant-access}}]]] - - ["/sessions" - ["" {:methods {"POST" :sessions/create}}] - ["/:session-id" - ["" {:methods {"GET" :sessions/get}}] - ["/messages" {:methods {"POST" :sessions/messages}}] - ["/pause" {:methods {"POST" :sessions/pause}}] - ["/resume" {:methods {"POST" :sessions/resume}}] - ["/interrupt" {:methods {"POST" :sessions/interrupt}}] - ["/cancel" {:methods {"POST" :sessions/cancel}}] - ["/pr" {:methods {"POST" :sessions/pr}}] - ["/events" {:methods {"GET" :sessions/events}}] - ["/terminal" {:methods {"GET" :sessions/terminal}}] - ["/stream" {:methods {"GET" :sessions/stream}}]]]]) + ["/grant-access" {:methods {"POST" :e2ee/grant-access}}]]]]) (def ^:private router (r/router route-data)) diff --git a/deps/db-sync/src/logseq/db_sync/worker/routes/sync.cljs b/deps/workers/src/logseq/sync/worker/routes/sync.cljs similarity index 94% rename from deps/db-sync/src/logseq/db_sync/worker/routes/sync.cljs rename to deps/workers/src/logseq/sync/worker/routes/sync.cljs index c11f5c2b20..5adacd4a63 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/routes/sync.cljs +++ b/deps/workers/src/logseq/sync/worker/routes/sync.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.worker.routes.sync +(ns logseq.sync.worker.routes.sync (:require [reitit.core :as r])) (def ^:private route-data diff --git a/deps/db-sync/src/logseq/db_sync/worker/timing.cljs b/deps/workers/src/logseq/sync/worker/timing.cljs similarity index 95% rename from deps/db-sync/src/logseq/db_sync/worker/timing.cljs rename to deps/workers/src/logseq/sync/worker/timing.cljs index 5bf0d9b7a1..28c64bd7ec 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/timing.cljs +++ b/deps/workers/src/logseq/sync/worker/timing.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.worker.timing) +(ns logseq.sync.worker.timing) (defn summary "Returns duration summary from `start-ms` to `end-ms` with ordered `steps`. diff --git a/deps/db-sync/src/logseq/db_sync/worker/ws.cljs b/deps/workers/src/logseq/sync/worker/ws.cljs similarity index 84% rename from deps/db-sync/src/logseq/db_sync/worker/ws.cljs rename to deps/workers/src/logseq/sync/worker/ws.cljs index 5c4846530b..dcfb7a2567 100644 --- a/deps/db-sync/src/logseq/db_sync/worker/ws.cljs +++ b/deps/workers/src/logseq/sync/worker/ws.cljs @@ -1,8 +1,8 @@ -(ns logseq.db-sync.worker.ws +(ns logseq.sync.worker.ws (:require [lambdaisland.glogi :as log] - [logseq.db-sync.malli-schema :as db-sync-schema] - [logseq.db-sync.protocol :as protocol] - [logseq.db-sync.worker.coerce :as coerce])) + [logseq.sync.malli-schema :as db-sync-schema] + [logseq.sync.protocol :as protocol] + [logseq.sync.worker.coerce :as coerce])) (defn ws-open? [ws] (= 1 (.-readyState ws))) diff --git a/deps/db-sync/start.sh b/deps/workers/start.sh similarity index 100% rename from deps/db-sync/start.sh rename to deps/workers/start.sh diff --git a/deps/db-sync/test/logseq/db_sync/worker_agents_dispatch_test.cljs b/deps/workers/test/logseq/agents/dispatch_test.cljs similarity index 90% rename from deps/db-sync/test/logseq/db_sync/worker_agents_dispatch_test.cljs rename to deps/workers/test/logseq/agents/dispatch_test.cljs index 3d211aae21..8b2d8a05b4 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_agents_dispatch_test.cljs +++ b/deps/workers/test/logseq/agents/dispatch_test.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.worker-agents-dispatch-test +(ns logseq.agents.dispatch-test (:require [cljs.test :refer [async deftest is]] - [logseq.db-sync.platform.core :as platform] - [logseq.db-sync.worker.agents-dispatch :as agents-dispatch])) + [logseq.sync.platform.core :as platform] + [logseq.agents.dispatch :as agents-dispatch])) (deftest agents-dispatch-health-test (async done diff --git a/deps/db-sync/test/logseq/db_sync/agent_do_test.cljs b/deps/workers/test/logseq/agents/do_test.cljs similarity index 99% rename from deps/db-sync/test/logseq/db_sync/agent_do_test.cljs rename to deps/workers/test/logseq/agents/do_test.cljs index 743d4147dd..c9626c779f 100644 --- a/deps/db-sync/test/logseq/db_sync/agent_do_test.cljs +++ b/deps/workers/test/logseq/agents/do_test.cljs @@ -1,9 +1,9 @@ -(ns logseq.db-sync.agent-do-test +(ns logseq.agents.do-test (:require [cljs.test :refer [async deftest is testing]] [clojure.string :as string] - [logseq.db-sync.worker.agent.do :as agent-do] - [logseq.db-sync.worker.agent.runtime-provider :as runtime-provider] - [logseq.db-sync.worker.agent.source-control :as source-control])) + [logseq.agents.do :as agent-do] + [logseq.agents.runtime-provider :as runtime-provider] + [logseq.agents.source-control :as source-control])) (defn- make-agent-storage [] (let [data (js/Map.)] diff --git a/deps/db-sync/test/logseq/db_sync/agent_request_test.cljs b/deps/workers/test/logseq/agents/request_test.cljs similarity index 95% rename from deps/db-sync/test/logseq/db_sync/agent_request_test.cljs rename to deps/workers/test/logseq/agents/request_test.cljs index 7e4be76150..8c4a4ce699 100644 --- a/deps/db-sync/test/logseq/db_sync/agent_request_test.cljs +++ b/deps/workers/test/logseq/agents/request_test.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.agent-request-test +(ns logseq.agents.request-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.worker.agent.request :as request] - [logseq.db-sync.worker.http :as http])) + [logseq.agents.request :as request] + [logseq.sync.worker.http :as http])) (deftest sessions-create-coerce-test (testing "accepts simplified sessions/create request" diff --git a/deps/workers/test/logseq/agents/routes_test.cljs b/deps/workers/test/logseq/agents/routes_test.cljs new file mode 100644 index 0000000000..f21f9ebf86 --- /dev/null +++ b/deps/workers/test/logseq/agents/routes_test.cljs @@ -0,0 +1,44 @@ +(ns logseq.agents.routes-test + (:require [cljs.test :refer [deftest is testing]] + [logseq.agents.routes :as routes])) + +(deftest match-route-sessions-test + (testing "sessions routes" + (let [match (routes/match-route "POST" "/sessions")] + (is (= :sessions/create (:handler match)))) + (let [match (routes/match-route "GET" "/sessions/session-1")] + (is (= :sessions/get (:handler match))) + (is (= "session-1" (get-in match [:path-params :session-id])))) + (let [match (routes/match-route "POST" "/sessions/session-2/messages")] + (is (= :sessions/messages (:handler match))) + (is (= "session-2" (get-in match [:path-params :session-id])))) + (let [match (routes/match-route "POST" "/sessions/session-3/cancel")] + (is (= :sessions/cancel (:handler match))) + (is (= "session-3" (get-in match [:path-params :session-id])))) + (let [match (routes/match-route "GET" "/sessions/session-4/stream")] + (is (= :sessions/stream (:handler match))) + (is (= "session-4" (get-in match [:path-params :session-id])))) + (let [match (routes/match-route "GET" "/sessions/session-5/terminal")] + (is (= :sessions/terminal (:handler match))) + (is (= "session-5" (get-in match [:path-params :session-id])))))) + +(deftest match-route-sessions-events-test + (testing "sessions events routes" + (let [match (routes/match-route "GET" "/sessions/session-9/events")] + (is (= :sessions/events (:handler match))) + (is (= "session-9" (get-in match [:path-params :session-id])))))) + +(deftest match-route-sessions-control-test + (testing "sessions control routes" + (let [match (routes/match-route "POST" "/sessions/session-10/pause")] + (is (= :sessions/pause (:handler match))) + (is (= "session-10" (get-in match [:path-params :session-id])))) + (let [match (routes/match-route "POST" "/sessions/session-11/resume")] + (is (= :sessions/resume (:handler match))) + (is (= "session-11" (get-in match [:path-params :session-id])))) + (let [match (routes/match-route "POST" "/sessions/session-12/interrupt")] + (is (= :sessions/interrupt (:handler match))) + (is (= "session-12" (get-in match [:path-params :session-id])))) + (let [match (routes/match-route "POST" "/sessions/session-13/pr")] + (is (= :sessions/pr (:handler match))) + (is (= "session-13" (get-in match [:path-params :session-id])))))) diff --git a/deps/db-sync/test/logseq/db_sync/agent_runtime_provider_test.cljs b/deps/workers/test/logseq/agents/runtime_provider_test.cljs similarity index 99% rename from deps/db-sync/test/logseq/db_sync/agent_runtime_provider_test.cljs rename to deps/workers/test/logseq/agents/runtime_provider_test.cljs index 484720c36a..d158440d6d 100644 --- a/deps/db-sync/test/logseq/db_sync/agent_runtime_provider_test.cljs +++ b/deps/workers/test/logseq/agents/runtime_provider_test.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.agent-runtime-provider-test +(ns logseq.agents.runtime-provider-test (:require [cljs.test :refer [async deftest is testing]] [clojure.string :as string] - [logseq.db-sync.worker.agent.runtime-provider :as runtime-provider])) + [logseq.agents.runtime-provider :as runtime-provider])) (defn- fetch-url [request] (cond diff --git a/deps/db-sync/test/logseq/db_sync/agent_sandbox_test.cljs b/deps/workers/test/logseq/agents/sandbox_test.cljs similarity index 94% rename from deps/db-sync/test/logseq/db_sync/agent_sandbox_test.cljs rename to deps/workers/test/logseq/agents/sandbox_test.cljs index 1b0d5ec0cf..24efdbbc94 100644 --- a/deps/db-sync/test/logseq/db_sync/agent_sandbox_test.cljs +++ b/deps/workers/test/logseq/agents/sandbox_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.agent-sandbox-test +(ns logseq.agents.sandbox-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.worker.agent.sandbox :as sandbox])) + [logseq.agents.sandbox :as sandbox])) (deftest normalize-base-url-test (testing "normalizes sandbox base urls" diff --git a/deps/db-sync/test/logseq/db_sync/agent_session_test.cljs b/deps/workers/test/logseq/agents/session_test.cljs similarity index 96% rename from deps/db-sync/test/logseq/db_sync/agent_session_test.cljs rename to deps/workers/test/logseq/agents/session_test.cljs index 0e19ec2dd5..d48c53e750 100644 --- a/deps/db-sync/test/logseq/db_sync/agent_session_test.cljs +++ b/deps/workers/test/logseq/agents/session_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.agent-session-test +(ns logseq.agents.session-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.worker.agent.session :as session])) + [logseq.agents.session :as session])) (deftest session-initialization-test (testing "builds a created session with task and audit" diff --git a/deps/db-sync/test/logseq/db_sync/agent_source_control_test.cljs b/deps/workers/test/logseq/agents/source_control_test.cljs similarity index 92% rename from deps/db-sync/test/logseq/db_sync/agent_source_control_test.cljs rename to deps/workers/test/logseq/agents/source_control_test.cljs index 83ee25619f..147adcc8b0 100644 --- a/deps/db-sync/test/logseq/db_sync/agent_source_control_test.cljs +++ b/deps/workers/test/logseq/agents/source_control_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.agent-source-control-test +(ns logseq.agents.source-control-test (:require [cljs.test :refer [async deftest is testing]] - [logseq.db-sync.worker.agent.source-control :as source-control])) + [logseq.agents.source-control :as source-control])) (deftest parse-github-repo-test (testing "parses github https and ssh repo urls" diff --git a/deps/db-sync/test/logseq/db_sync/batch_test.cljs b/deps/workers/test/logseq/sync/batch_test.cljs similarity index 89% rename from deps/db-sync/test/logseq/db_sync/batch_test.cljs rename to deps/workers/test/logseq/sync/batch_test.cljs index af88a6b0f4..51ab5d6b87 100644 --- a/deps/db-sync/test/logseq/db_sync/batch_test.cljs +++ b/deps/workers/test/logseq/sync/batch_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.batch-test +(ns logseq.sync.batch-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.batch :as batch])) + [logseq.sync.batch :as batch])) (deftest rows->insert-batches-test (testing "splits rows into batches based on max params" diff --git a/deps/db-sync/test/logseq/db_sync/common_test.cljs b/deps/workers/test/logseq/sync/common_test.cljs similarity index 98% rename from deps/db-sync/test/logseq/db_sync/common_test.cljs rename to deps/workers/test/logseq/sync/common_test.cljs index 1b1a91992b..c6abf0daae 100644 --- a/deps/db-sync/test/logseq/db_sync/common_test.cljs +++ b/deps/workers/test/logseq/sync/common_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.common-test +(ns logseq.sync.common-test (:require [cljs.test :refer [async deftest is]] - [logseq.db-sync.common :as common] + [logseq.sync.common :as common] [promesa.core :as p])) (defn- make-stmt [calls result] diff --git a/deps/db-sync/test/logseq/db_sync/cycle_test.cljs b/deps/workers/test/logseq/sync/cycle_test.cljs similarity index 99% rename from deps/db-sync/test/logseq/db_sync/cycle_test.cljs rename to deps/workers/test/logseq/sync/cycle_test.cljs index 526d10388d..e32704115f 100644 --- a/deps/db-sync/test/logseq/db_sync/cycle_test.cljs +++ b/deps/workers/test/logseq/sync/cycle_test.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.cycle-test +(ns logseq.sync.cycle-test (:require [cljs.test :refer [deftest is testing]] [datascript.core :as d] - [logseq.db-sync.cycle :as cycle] + [logseq.sync.cycle :as cycle] [logseq.db.test.helper :as db-test])) (defn- new-conn [] diff --git a/deps/db-sync/test/logseq/db_sync/index_test.cljs b/deps/workers/test/logseq/sync/index_test.cljs similarity index 97% rename from deps/db-sync/test/logseq/db_sync/index_test.cljs rename to deps/workers/test/logseq/sync/index_test.cljs index c2fa575128..b4bc129e18 100644 --- a/deps/db-sync/test/logseq/db_sync/index_test.cljs +++ b/deps/workers/test/logseq/sync/index_test.cljs @@ -1,8 +1,8 @@ -(ns logseq.db-sync.index-test +(ns logseq.sync.index-test (:require [cljs.test :refer [async deftest is]] [clojure.string :as string] - [logseq.db-sync.common :as common] - [logseq.db-sync.index :as index] + [logseq.sync.common :as common] + [logseq.sync.index :as index] [promesa.core :as p])) (def ^:private graph-e2ee-migration-sql diff --git a/deps/db-sync/test/logseq/db_sync/node_adapter_test.cljs b/deps/workers/test/logseq/sync/node_adapter_test.cljs similarity index 97% rename from deps/db-sync/test/logseq/db_sync/node_adapter_test.cljs rename to deps/workers/test/logseq/sync/node_adapter_test.cljs index b4de5212cc..b3ce309156 100644 --- a/deps/db-sync/test/logseq/db_sync/node_adapter_test.cljs +++ b/deps/workers/test/logseq/sync/node_adapter_test.cljs @@ -1,10 +1,10 @@ -(ns logseq.db-sync.node-adapter-test +(ns logseq.sync.node-adapter-test ;; Linters disabled because commented out FIXME code causes false positives {:clj-kondo/config {:ignore true}} (:require [cljs.test :refer [deftest is async testing]] [clojure.string :as string] - [logseq.db-sync.node.server :as node-server] - [logseq.db-sync.protocol :as protocol] + [logseq.sync.node.server :as node-server] + [logseq.sync.protocol :as protocol] [promesa.core :as p])) (def test-token "test-token") diff --git a/deps/db-sync/test/logseq/db_sync/node_config_test.cljs b/deps/workers/test/logseq/sync/node_config_test.cljs similarity index 92% rename from deps/db-sync/test/logseq/db_sync/node_config_test.cljs rename to deps/workers/test/logseq/sync/node_config_test.cljs index 1c9c3880a7..41f4021521 100644 --- a/deps/db-sync/test/logseq/db_sync/node_config_test.cljs +++ b/deps/workers/test/logseq/sync/node_config_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.node-config-test +(ns logseq.sync.node-config-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.node.config :as config])) + [logseq.sync.node.config :as config])) (defn- throws? [f] (try diff --git a/deps/workers/test/logseq/sync/node_server_test.cljs b/deps/workers/test/logseq/sync/node_server_test.cljs new file mode 100644 index 0000000000..a3c42c2e93 --- /dev/null +++ b/deps/workers/test/logseq/sync/node_server_test.cljs @@ -0,0 +1,110 @@ +(ns logseq.sync.node-server-test + (:require [cljs.test :refer [async deftest is]] + [logseq.sync.node.server :as node-server] + [promesa.core :as p])) + +(defn- fetch-with-timeout [url timeout-ms token] + (let [timeout-sentinel ::timeout] + {:sentinel timeout-sentinel + :promise (js/Promise. + (fn [resolve reject] + (let [controller (js/AbortController.) + timeout-id (js/setTimeout + (fn [] + (.abort controller)) + timeout-ms)] + (-> (js/fetch url #js {:method "GET" + :headers #js {"authorization" (str "Bearer " token)} + :signal (.-signal controller)}) + (.then (fn [response] + (js/clearTimeout timeout-id) + (resolve response))) + (.catch (fn [error] + (js/clearTimeout timeout-id) + (if (= "AbortError" (.-name error)) + (resolve timeout-sentinel) + (reject error))))))))})) + +(defn- base64url-encode [text] + (-> (.from js/Buffer text "utf8") + (.toString "base64") + (.replace #"/" "_") + (.replace #"\+" "-") + (.replace #"=+$" ""))) + +(defn- invalid-jwks-token [] + (let [header (base64url-encode "{\"alg\":\"RS256\",\"kid\":\"k1\"}") + payload (base64url-encode "{\"iss\":\"iss\",\"aud\":\"aud\",\"exp\":4070908800}")] + (str header "." payload ".sig"))) + +(deftest node-server-returns-500-when-auth-claims-rejects-test + (async done + (let [stop-server! (atom nil) + token (invalid-jwks-token)] + (-> (p/let [{:keys [base-url stop!]} (node-server/start! {:port 0 + :data-dir (str "tmp/db-sync-node-server-test/" (random-uuid)) + :cognito-issuer "iss" + :cognito-client-id "aud" + :cognito-jwks-url "http://127.0.0.1:1/.well-known/jwks.json"}) + _ (reset! stop-server! stop!) + {:keys [promise sentinel]} (fetch-with-timeout (str base-url "/graphs") 1200 token) + response promise] + (if (identical? response sentinel) + (is false "request timed out") + (p/let [body (.json response)] + (is (= 500 (.-status response))) + (is (= "server error" (aget body "error")))))) + (p/catch + (fn [error] + (is false (str error)))) + (p/then + (fn [] + (if-let [stop! @stop-server!] + (-> (stop!) + (p/catch (fn [error] + (is false (str error))))) + nil))) + (p/then + (fn [] + (done))))))) + +(deftest node-server-logs-request-failed-marker-when-auth-claims-rejects-test + (async done + (let [stop-server! (atom nil) + original-console-error (.-error js/console) + logged-errors (atom []) + token (invalid-jwks-token)] + (aset js/console + "error" + (fn [& args] + (swap! logged-errors conj args))) + (-> (p/let [{:keys [base-url stop!]} (node-server/start! {:port 0 + :data-dir (str "tmp/db-sync-node-server-log-test/" (random-uuid)) + :cognito-issuer "iss" + :cognito-client-id "aud" + :cognito-jwks-url "http://127.0.0.1:1/.well-known/jwks.json"}) + _ (reset! stop-server! stop!) + _ (reset! logged-errors []) + {:keys [promise sentinel]} (fetch-with-timeout (str base-url "/graphs") 1200 token) + response promise] + (if (identical? response sentinel) + (is false "request timed out") + (do + (is (= 500 (.-status response))) + (is (some #(= ":db-sync/node-request-failed" (first %)) + @logged-errors))))) + (p/catch + (fn [error] + (aset js/console "error" original-console-error) + (is false (str error)))) + (p/then + (fn [] + (aset js/console "error" original-console-error) + (if-let [stop! @stop-server!] + (-> (stop!) + (p/catch (fn [error] + (is false (str error))))) + nil))) + (p/then + (fn [] + (done))))))) diff --git a/deps/db-sync/test/logseq/db_sync/normalize_test.cljs b/deps/workers/test/logseq/sync/normalize_test.cljs similarity index 98% rename from deps/db-sync/test/logseq/db_sync/normalize_test.cljs rename to deps/workers/test/logseq/sync/normalize_test.cljs index c2110c4a2f..283b41a644 100644 --- a/deps/db-sync/test/logseq/db_sync/normalize_test.cljs +++ b/deps/workers/test/logseq/sync/normalize_test.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.normalize-test +(ns logseq.sync.normalize-test (:require [cljs.test :refer [deftest is testing]] [datascript.core :as d] [logseq.db.common.normalize :as db-normalize] diff --git a/deps/db-sync/test/logseq/db_sync/platform_test.cljs b/deps/workers/test/logseq/sync/platform_test.cljs similarity index 87% rename from deps/db-sync/test/logseq/db_sync/platform_test.cljs rename to deps/workers/test/logseq/sync/platform_test.cljs index b2e63b5549..6b7d2abf1f 100644 --- a/deps/db-sync/test/logseq/db_sync/platform_test.cljs +++ b/deps/workers/test/logseq/sync/platform_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.platform-test +(ns logseq.sync.platform-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.platform.core :as platform])) + [logseq.sync.platform.core :as platform])) (deftest platform-response-test (testing "response builds status and headers" diff --git a/deps/db-sync/test/logseq/db_sync/snapshot_test.cljs b/deps/workers/test/logseq/sync/snapshot_test.cljs similarity index 96% rename from deps/db-sync/test/logseq/db_sync/snapshot_test.cljs rename to deps/workers/test/logseq/sync/snapshot_test.cljs index 2721c67327..97913b0522 100644 --- a/deps/db-sync/test/logseq/db_sync/snapshot_test.cljs +++ b/deps/workers/test/logseq/sync/snapshot_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.snapshot-test +(ns logseq.sync.snapshot-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.snapshot :as snapshot])) + [logseq.sync.snapshot :as snapshot])) (deftest transit-frame-roundtrip-test (testing "framed transit json roundtrips rows" diff --git a/deps/db-sync/test/logseq/db_sync/storage_test.cljs b/deps/workers/test/logseq/sync/storage_test.cljs similarity index 82% rename from deps/db-sync/test/logseq/db_sync/storage_test.cljs rename to deps/workers/test/logseq/sync/storage_test.cljs index aa7a2bf2b7..dc03a2ef6f 100644 --- a/deps/db-sync/test/logseq/db_sync/storage_test.cljs +++ b/deps/workers/test/logseq/sync/storage_test.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.storage-test +(ns logseq.sync.storage-test (:require [cljs.test :refer [deftest is]] - [logseq.db-sync.storage :as storage] - [logseq.db-sync.test-sql :as test-sql])) + [logseq.sync.storage :as storage] + [logseq.sync.test-sql :as test-sql])) (deftest t-counter-test (let [sql (test-sql/make-sql)] diff --git a/deps/workers/test/logseq/sync/test_runner.cljs b/deps/workers/test/logseq/sync/test_runner.cljs new file mode 100644 index 0000000000..3a04ef05b7 --- /dev/null +++ b/deps/workers/test/logseq/sync/test_runner.cljs @@ -0,0 +1,32 @@ +(ns logseq.sync.test-runner + (:require [cljs.test :as ct] + [logseq.sync.common-test] + [logseq.sync.index-test] + [logseq.sync.node-adapter-test] + [logseq.sync.node-config-test] + [logseq.sync.normalize-test] + [logseq.sync.platform-test] + [logseq.sync.worker-auth-test] + [logseq.sync.worker-handler-assets-test] + [logseq.sync.worker-handler-index-test] + [logseq.sync.worker-handler-sync-test] + [logseq.sync.worker-handler-ws-test] + [logseq.sync.worker-routes-test] + [shadow.test :as st] + [shadow.test.env :as env])) + +(derive ::node ::ct/default) + +(defmethod ct/report [::node :end-run-tests] [m] + (if (ct/successful? m) + (js/process.exit 0) + (js/process.exit 1))) + +(defn ^:dev/after-load reset-test-data! [] + (when-let [test-data (env/get-test-data)] + (env/reset-test-data! test-data))) + +(defn main [& _args] + (reset-test-data!) + (let [test-env (ct/empty-env ::node)] + (st/run-all-tests test-env nil))) diff --git a/deps/db-sync/test/logseq/db_sync/test_sql.cljs b/deps/workers/test/logseq/sync/test_sql.cljs similarity index 98% rename from deps/db-sync/test/logseq/db_sync/test_sql.cljs rename to deps/workers/test/logseq/sync/test_sql.cljs index 99e5ee6cea..bd224f9e1a 100644 --- a/deps/db-sync/test/logseq/db_sync/test_sql.cljs +++ b/deps/workers/test/logseq/sync/test_sql.cljs @@ -1,4 +1,4 @@ -(ns logseq.db-sync.test-sql +(ns logseq.sync.test-sql (:require [clojure.string :as string])) (defn- js-key [k] diff --git a/deps/db-sync/test/logseq/db_sync/worker_auth_test.cljs b/deps/workers/test/logseq/sync/worker_auth_test.cljs similarity index 97% rename from deps/db-sync/test/logseq/db_sync/worker_auth_test.cljs rename to deps/workers/test/logseq/sync/worker_auth_test.cljs index da187c325e..b968169429 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_auth_test.cljs +++ b/deps/workers/test/logseq/sync/worker_auth_test.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.worker-auth-test +(ns logseq.sync.worker-auth-test (:require [cljs.test :refer [async deftest is]] [logseq.common.authorization :as authorization] - [logseq.db-sync.worker.auth :as auth] + [logseq.sync.worker.auth :as auth] [promesa.core :as p])) (deftest auth-claims-uses-jwt-verification-test diff --git a/deps/db-sync/test/logseq/db_sync/worker_handler_assets_test.cljs b/deps/workers/test/logseq/sync/worker_handler_assets_test.cljs similarity index 90% rename from deps/db-sync/test/logseq/db_sync/worker_handler_assets_test.cljs rename to deps/workers/test/logseq/sync/worker_handler_assets_test.cljs index a792284884..33330e549a 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_handler_assets_test.cljs +++ b/deps/workers/test/logseq/sync/worker_handler_assets_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.worker-handler-assets-test +(ns logseq.sync.worker-handler-assets-test (:require [cljs.test :refer [async deftest is]] - [logseq.db-sync.worker.handler.assets :as assets] + [logseq.sync.worker.handler.assets :as assets] [promesa.core :as p])) (deftest assets-get-includes-content-length-header-test diff --git a/deps/db-sync/test/logseq/db_sync/worker_handler_index_test.cljs b/deps/workers/test/logseq/sync/worker_handler_index_test.cljs similarity index 93% rename from deps/db-sync/test/logseq/db_sync/worker_handler_index_test.cljs rename to deps/workers/test/logseq/sync/worker_handler_index_test.cljs index a2f6f143fb..c852532c16 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_handler_index_test.cljs +++ b/deps/workers/test/logseq/sync/worker_handler_index_test.cljs @@ -1,8 +1,8 @@ -(ns logseq.db-sync.worker-handler-index-test +(ns logseq.sync.worker-handler-index-test (:require [cljs.test :refer [async deftest is]] - [logseq.db-sync.index :as index] - [logseq.db-sync.worker.auth :as auth] - [logseq.db-sync.worker.handler.index :as index-handler] + [logseq.sync.index :as index] + [logseq.sync.worker.auth :as auth] + [logseq.sync.worker.handler.index :as index-handler] [promesa.core :as p])) (deftest graph-access-response-with-timing-caches-result-test diff --git a/deps/db-sync/test/logseq/db_sync/worker_handler_sync_test.cljs b/deps/workers/test/logseq/sync/worker_handler_sync_test.cljs similarity index 96% rename from deps/db-sync/test/logseq/db_sync/worker_handler_sync_test.cljs rename to deps/workers/test/logseq/sync/worker_handler_sync_test.cljs index bc60f0ee33..cd34ca0819 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_handler_sync_test.cljs +++ b/deps/workers/test/logseq/sync/worker_handler_sync_test.cljs @@ -1,8 +1,8 @@ -(ns logseq.db-sync.worker-handler-sync-test +(ns logseq.sync.worker-handler-sync-test (:require [cljs.test :refer [async deftest is]] - [logseq.db-sync.common :as common] - [logseq.db-sync.storage :as storage] - [logseq.db-sync.worker.handler.sync :as sync-handler] + [logseq.sync.common :as common] + [logseq.sync.storage :as storage] + [logseq.sync.worker.handler.sync :as sync-handler] [promesa.core :as p])) (defn- empty-sql [] diff --git a/deps/db-sync/test/logseq/db_sync/worker_handler_ws_test.cljs b/deps/workers/test/logseq/sync/worker_handler_ws_test.cljs similarity index 79% rename from deps/db-sync/test/logseq/db_sync/worker_handler_ws_test.cljs rename to deps/workers/test/logseq/sync/worker_handler_ws_test.cljs index 9b442a2813..9b18ee1c24 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_handler_ws_test.cljs +++ b/deps/workers/test/logseq/sync/worker_handler_ws_test.cljs @@ -1,9 +1,9 @@ -(ns logseq.db-sync.worker-handler-ws-test +(ns logseq.sync.worker-handler-ws-test (:require [cljs.test :refer [deftest is]] - [logseq.db-sync.protocol :as protocol] - [logseq.db-sync.worker.handler.ws :as ws-handler] - [logseq.db-sync.worker.presence :as presence] - [logseq.db-sync.worker.ws :as ws])) + [logseq.sync.protocol :as protocol] + [logseq.sync.worker.handler.ws :as ws-handler] + [logseq.sync.worker.presence :as presence] + [logseq.sync.worker.ws :as ws])) (deftest presence-message-broadcast-excludes-source-client-test (let [source-ws #js {:readyState 1} diff --git a/deps/db-sync/test/logseq/db_sync/worker_routes_test.cljs b/deps/workers/test/logseq/sync/worker_routes_test.cljs similarity index 51% rename from deps/db-sync/test/logseq/db_sync/worker_routes_test.cljs rename to deps/workers/test/logseq/sync/worker_routes_test.cljs index da85cf1005..5decc77ea7 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_routes_test.cljs +++ b/deps/workers/test/logseq/sync/worker_routes_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.worker-routes-test +(ns logseq.sync.worker-routes-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.worker.routes.index :as routes])) + [logseq.sync.worker.routes.index :as routes])) (deftest match-route-graphs-test (testing "graphs routes" @@ -46,44 +46,3 @@ (testing "method mismatch returns nil" (is (nil? (routes/match-route "GET" "/graphs/graph-1/members/user-9"))) (is (nil? (routes/match-route "PUT" "/e2ee/user-keys"))))) - -(deftest match-route-sessions-test - (testing "sessions routes" - (let [match (routes/match-route "POST" "/sessions")] - (is (= :sessions/create (:handler match)))) - (let [match (routes/match-route "GET" "/sessions/session-1")] - (is (= :sessions/get (:handler match))) - (is (= "session-1" (get-in match [:path-params :session-id])))) - (let [match (routes/match-route "POST" "/sessions/session-2/messages")] - (is (= :sessions/messages (:handler match))) - (is (= "session-2" (get-in match [:path-params :session-id])))) - (let [match (routes/match-route "POST" "/sessions/session-3/cancel")] - (is (= :sessions/cancel (:handler match))) - (is (= "session-3" (get-in match [:path-params :session-id])))) - (let [match (routes/match-route "GET" "/sessions/session-4/stream")] - (is (= :sessions/stream (:handler match))) - (is (= "session-4" (get-in match [:path-params :session-id])))) - (let [match (routes/match-route "GET" "/sessions/session-5/terminal")] - (is (= :sessions/terminal (:handler match))) - (is (= "session-5" (get-in match [:path-params :session-id])))))) - -(deftest match-route-sessions-events-test - (testing "sessions events routes" - (let [match (routes/match-route "GET" "/sessions/session-9/events")] - (is (= :sessions/events (:handler match))) - (is (= "session-9" (get-in match [:path-params :session-id])))))) - -(deftest match-route-sessions-control-test - (testing "sessions control routes" - (let [match (routes/match-route "POST" "/sessions/session-10/pause")] - (is (= :sessions/pause (:handler match))) - (is (= "session-10" (get-in match [:path-params :session-id])))) - (let [match (routes/match-route "POST" "/sessions/session-11/resume")] - (is (= :sessions/resume (:handler match))) - (is (= "session-11" (get-in match [:path-params :session-id])))) - (let [match (routes/match-route "POST" "/sessions/session-12/interrupt")] - (is (= :sessions/interrupt (:handler match))) - (is (= "session-12" (get-in match [:path-params :session-id])))) - (let [match (routes/match-route "POST" "/sessions/session-13/pr")] - (is (= :sessions/pr (:handler match))) - (is (= "session-13" (get-in match [:path-params :session-id])))))) diff --git a/deps/db-sync/test/logseq/db_sync/worker_split_test_runner.cljs b/deps/workers/test/logseq/sync/worker_split_test_runner.cljs similarity index 78% rename from deps/db-sync/test/logseq/db_sync/worker_split_test_runner.cljs rename to deps/workers/test/logseq/sync/worker_split_test_runner.cljs index 8d577df21b..c3955eca3f 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_split_test_runner.cljs +++ b/deps/workers/test/logseq/sync/worker_split_test_runner.cljs @@ -1,7 +1,7 @@ -(ns logseq.db-sync.worker-split-test-runner +(ns logseq.sync.worker-split-test-runner (:require [cljs.test :as ct] - [logseq.db-sync.worker-agents-dispatch-test] - [logseq.db-sync.worker-test] + [logseq.agents.dispatch-test] + [logseq.sync.worker-test] [shadow.test :as st] [shadow.test.env :as env])) diff --git a/deps/db-sync/test/logseq/db_sync/worker_sync_routes_test.cljs b/deps/workers/test/logseq/sync/worker_sync_routes_test.cljs similarity index 91% rename from deps/db-sync/test/logseq/db_sync/worker_sync_routes_test.cljs rename to deps/workers/test/logseq/sync/worker_sync_routes_test.cljs index f6357ce3a6..a8955d5ad0 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_sync_routes_test.cljs +++ b/deps/workers/test/logseq/sync/worker_sync_routes_test.cljs @@ -1,6 +1,6 @@ -(ns logseq.db-sync.worker-sync-routes-test +(ns logseq.sync.worker-sync-routes-test (:require [cljs.test :refer [deftest is testing]] - [logseq.db-sync.worker.routes.sync :as sync-routes])) + [logseq.sync.worker.routes.sync :as sync-routes])) (deftest match-route-sync-test (testing "sync routes" diff --git a/deps/db-sync/test/logseq/db_sync/worker_test.cljs b/deps/workers/test/logseq/sync/worker_test.cljs similarity index 96% rename from deps/db-sync/test/logseq/db_sync/worker_test.cljs rename to deps/workers/test/logseq/sync/worker_test.cljs index 16c4b60656..28c0471a8e 100644 --- a/deps/db-sync/test/logseq/db_sync/worker_test.cljs +++ b/deps/workers/test/logseq/sync/worker_test.cljs @@ -1,9 +1,9 @@ -(ns logseq.db-sync.worker-test +(ns logseq.sync.worker-test (:require [cljs.test :refer [async deftest is]] [datascript.core :as d] - [logseq.db-sync.order :as sync-order] - [logseq.db-sync.platform.core :as platform] - [logseq.db-sync.worker.dispatch :as dispatch] + [logseq.sync.order :as sync-order] + [logseq.sync.platform.core :as platform] + [logseq.sync.worker.dispatch :as dispatch] [logseq.db.common.order :as db-order] [logseq.db.frontend.schema :as db-schema])) diff --git a/deps/db-sync/worker/Dockerfile.sandbox-agent b/deps/workers/worker/Dockerfile.sandbox-agent similarity index 100% rename from deps/db-sync/worker/Dockerfile.sandbox-agent rename to deps/workers/worker/Dockerfile.sandbox-agent diff --git a/deps/db-sync/worker/migrations/0001_init.sql b/deps/workers/worker/migrations/0001_init.sql similarity index 100% rename from deps/db-sync/worker/migrations/0001_init.sql rename to deps/workers/worker/migrations/0001_init.sql diff --git a/deps/db-sync/worker/migrations/0002_add_graph_e2ee.sql b/deps/workers/worker/migrations/0002_add_graph_e2ee.sql similarity index 100% rename from deps/db-sync/worker/migrations/0002_add_graph_e2ee.sql rename to deps/workers/worker/migrations/0002_add_graph_e2ee.sql diff --git a/deps/db-sync/worker/scripts/ws_test.js b/deps/workers/worker/scripts/ws_test.js similarity index 100% rename from deps/db-sync/worker/scripts/ws_test.js rename to deps/workers/worker/scripts/ws_test.js diff --git a/deps/db-sync/worker/wrangler.agents.toml b/deps/workers/worker/wrangler.agents.toml similarity index 100% rename from deps/db-sync/worker/wrangler.agents.toml rename to deps/workers/worker/wrangler.agents.toml diff --git a/deps/db-sync/worker/wrangler.toml b/deps/workers/worker/wrangler.toml similarity index 100% rename from deps/db-sync/worker/wrangler.toml rename to deps/workers/worker/wrangler.toml diff --git a/deps/db-sync/yarn.lock b/deps/workers/yarn.lock similarity index 100% rename from deps/db-sync/yarn.lock rename to deps/workers/yarn.lock diff --git a/docs/agent-guide/001-db-sync-nodejs-adapter.md b/docs/agent-guide/001-db-sync-nodejs-adapter.md index 7a114b55fc..5a04c6ec45 100644 --- a/docs/agent-guide/001-db-sync-nodejs-adapter.md +++ b/docs/agent-guide/001-db-sync-nodejs-adapter.md @@ -40,21 +40,21 @@ The Node entrypoint will be responsible only for server lifecycle and wiring ada +------------------------+ ## Implementation Plan -1. Read docs/agent-guide/db-sync/db-sync-guide.md and docs/agent-guide/db-sync/protocol.md and list the Cloudflare-specific APIs used by the worker in deps/db-sync/src/logseq/db_sync/worker/. -2. Create a platform abstraction namespace in deps/db-sync/src/logseq/db_sync/platform/core.cljs that defines the minimal request, response, and WebSocket operations used by handlers. -3. Add a Cloudflare platform adapter in deps/db-sync/src/logseq/db_sync/platform/cloudflare.cljs that wraps the current Worker Request, Response, and WebSocket types. -4. Add a Node platform adapter in deps/db-sync/src/logseq/db_sync/platform/node.cljs that wraps Node HTTP requests, responses, and WebSocket connections. -5. Update deps/db-sync/src/logseq/db_sync/worker/dispatch.cljs and deps/db-sync/src/logseq/db_sync/worker/http.cljs to depend on the platform abstraction instead of direct Worker APIs. -6. Add a Node server entrypoint in deps/db-sync/src/logseq/db_sync/node/entry.cljs that sets up HTTP routes, WS upgrade handling, and lifecycle start/stop. -7. Add a Node routing layer in deps/db-sync/src/logseq/db_sync/node/routes.cljs that maps incoming requests to the existing worker route handlers. -8. Introduce configuration parsing in deps/db-sync/src/logseq/db_sync/node/config.cljs to select storage and auth drivers via environment variables. -9. Add Node adapter implementations for storage and assets in deps/db-sync/src/logseq/db_sync/node/storage.cljs and deps/db-sync/src/logseq/db_sync/node/assets.cljs that map to the existing storage interfaces. -10. Add a new shadow-cljs build target in deps/db-sync/shadow-cljs.edn for the Node adapter output. -11. Add build and run scripts to deps/db-sync/package.json for the Node adapter, including a dev watch command. +1. Read docs/agent-guide/db-sync/db-sync-guide.md and docs/agent-guide/db-sync/protocol.md and list the Cloudflare-specific APIs used by the worker in deps/workers/src/logseq/sync/worker/. +2. Create a platform abstraction namespace in deps/workers/src/logseq/sync/platform/core.cljs that defines the minimal request, response, and WebSocket operations used by handlers. +3. Add a Cloudflare platform adapter in deps/workers/src/logseq/sync/platform/cloudflare.cljs that wraps the current Worker Request, Response, and WebSocket types. +4. Add a Node platform adapter in deps/workers/src/logseq/sync/platform/node.cljs that wraps Node HTTP requests, responses, and WebSocket connections. +5. Update deps/workers/src/logseq/sync/worker/dispatch.cljs and deps/workers/src/logseq/sync/worker/http.cljs to depend on the platform abstraction instead of direct Worker APIs. +6. Add a Node server entrypoint in deps/workers/src/logseq/sync/node/entry.cljs that sets up HTTP routes, WS upgrade handling, and lifecycle start/stop. +7. Add a Node routing layer in deps/workers/src/logseq/sync/node/routes.cljs that maps incoming requests to the existing worker route handlers. +8. Introduce configuration parsing in deps/workers/src/logseq/sync/node/config.cljs to select storage and auth drivers via environment variables. +9. Add Node adapter implementations for storage and assets in deps/workers/src/logseq/sync/node/storage.cljs and deps/workers/src/logseq/sync/node/assets.cljs that map to the existing storage interfaces. +10. Add a new shadow-cljs build target in deps/workers/shadow-cljs.edn for the Node adapter output. +11. Add build and run scripts to deps/workers/package.json for the Node adapter, including a dev watch command. 12. Update docs/agent-guide/db-sync/db-sync-guide.md with the new local dev and test commands for the Node adapter. 13. Add a new self-hosting section to docs/develop-logseq.md with minimal steps to run the Node adapter. -14. Add integration tests under deps/db-sync/test/logseq/db_sync/node_adapter_test.cljs that launch the Node adapter and exercise HTTP and WS paths. -15. Add unit tests under deps/db-sync/test/logseq/db_sync/platform_test.cljs that cover request normalization and error propagation. +14. Add integration tests under deps/workers/test/logseq/sync/node_adapter_test.cljs that launch the Node adapter and exercise HTTP and WS paths. +15. Add unit tests under deps/workers/test/logseq/sync/platform_test.cljs that cover request normalization and error propagation. 16. Run the tests using the commands listed in the Verification section and confirm they fail before implementation and pass after implementation. ## Configuration Matrix @@ -83,7 +83,7 @@ Expected result is a zero exit code and no failing tests. Run the Node adapter integration tests. ```bash -cd deps/db-sync +cd deps/workers npm run test:node-adapter ``` @@ -103,7 +103,7 @@ These tests validate observable behavior and response shapes instead of internal ## Implementation Details - Introduce a platform interface to normalize request, response, and WebSocket operations. -- Keep all protocol validation and handler logic inside deps/db-sync/src/logseq/db_sync/worker to avoid divergence. +- Keep all protocol validation and handler logic inside deps/workers/src/logseq/sync/worker to avoid divergence. - Make the Node entrypoint responsible only for wiring and lifecycle. - Add configuration parsing and driver selection in Node-specific namespaces. - Add a new shadow-cljs build target for the Node adapter output. diff --git a/docs/agent-guide/003-agent-service.md b/docs/agent-guide/003-agent-service.md index 3ae23f0a7d..f9424ebee4 100644 --- a/docs/agent-guide/003-agent-service.md +++ b/docs/agent-guide/003-agent-service.md @@ -176,7 +176,7 @@ Errors and idempotency: }, "execution": { "repo": "logseq/web", - "workdir": "deps/db-sync", + "workdir": "deps/workers", "env": { "LOGSEQ_GRAPH": "main" }, diff --git a/docs/agent-guide/004-m14-git-push-pr.md b/docs/agent-guide/004-m14-git-push-pr.md index fa07cc7971..ef2748919b 100644 --- a/docs/agent-guide/004-m14-git-push-pr.md +++ b/docs/agent-guide/004-m14-git-push-pr.md @@ -6,7 +6,7 @@ Architecture: Add a session-level publish endpoint that orchestrates push and PR Tech Stack: ClojureScript Worker + Durable Objects, existing runtime providers (`sprites`, `cloudflare`, `local-dev`), Git CLI in sandbox, GitHub REST API, Malli request and response coercion. -Related: Builds on `deps/db-sync/docs/milestones/agents/14-m14-git-push-and-optional-pr.md`, `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs`, and `deps/db-sync/src/logseq/db_sync/worker/agent/runtime_provider.cljs`. +Related: Builds on `deps/workers/docs/milestones/agents/14-m14-git-push-and-optional-pr.md`, `deps/workers/src/logseq/agents/do.cljs`, and `deps/workers/src/logseq/agents/runtime_provider.cljs`. ## Problem statement Current agent milestones stop at local commit behavior inside session sandboxes and do not provide a first-class publish flow. @@ -22,15 +22,15 @@ The missing pieces are publish-specific API routes, source-control provider logi ## Testing Plan I will follow @test-driven-development for every implementation slice, running RED, GREEN, and REFACTOR in small batches. -I will add route-level tests to verify `/sessions/:session-id/pr` matching and handler wiring in `deps/db-sync/test/logseq/db_sync/worker_routes_test.cljs`. +I will add route-level tests to verify `/sessions/:session-id/pr` matching and handler wiring in `deps/workers/test/logseq/sync/worker_routes_test.cljs`. -I will add schema coercion tests for publish request and response payloads in `deps/db-sync/test/logseq/db_sync/agent_request_test.cljs` and new targeted schema tests if needed. +I will add schema coercion tests for publish request and response payloads in `deps/workers/test/logseq/agents/request_test.cljs` and new targeted schema tests if needed. -I will add runtime-provider tests for push command assembly and provider-specific execution behavior in `deps/db-sync/test/logseq/db_sync/agent_runtime_provider_test.cljs`. +I will add runtime-provider tests for push command assembly and provider-specific execution behavior in `deps/workers/test/logseq/agents/runtime_provider_test.cljs`. -I will add Agent Session DO behavior tests for push success, push failure, PR success, manual PR fallback, and no-role-gate behavior in `deps/db-sync/test/logseq/db_sync/agent_do_test.cljs`. +I will add Agent Session DO behavior tests for push success, push failure, PR success, manual PR fallback, and no-role-gate behavior in `deps/workers/test/logseq/agents/do_test.cljs`. -I will add source-control unit tests for repo URL parsing, branch sanitization, PR URL fallback, and GitHub API error mapping in a new test namespace under `deps/db-sync/test/logseq/db_sync/`. +I will add source-control unit tests for repo URL parsing, branch sanitization, PR URL fallback, and GitHub API error mapping in a new test namespace under `deps/workers/test/logseq/sync/`. I will add a lightweight frontend behavior test or deterministic handler-level test for publish action dispatch if the current frontend test harness supports it, otherwise I will document manual verification steps. @@ -47,7 +47,7 @@ We will reuse the architectural pattern but adapt it to db-sync’s simpler sess | Pattern from background-agents | Where it appears | M14 decision in db-sync | | --- | --- | --- | -| Provider abstraction for source control operations. | `packages/control-plane/src/source-control/types.ts`. | Adopt with a smaller GitHub-first interface in `deps/db-sync/src/logseq/db_sync/worker/agent/source_control.cljs`. | +| Provider abstraction for source control operations. | `packages/control-plane/src/source-control/types.ts`. | Adopt with a smaller GitHub-first interface in `deps/workers/src/logseq/agents/source_control.cljs`. | | Session endpoint that performs push then PR. | `POST /sessions/:id/pr` in `packages/control-plane/src/router.ts`. | Adopt with `POST /sessions/:session-id/pr` in db-sync routes and DO handler. | | Push auth separated from PR auth. | `generatePushAuth()` and user OAuth in `durable-object.ts`. | Adapt by using server-side configured credentials for both push and PR in M14, with manual PR fallback when PR creds are missing. | | Branch sanitization and precedence rules. | `branch-resolution.ts`. | Adopt equivalent sanitization and head-branch resolution helpers in db-sync. | @@ -135,106 +135,106 @@ SSE /sessions/:id/stream This section is intentionally bite-sized so each step is a 2-5 minute action. ### Phase 1: Request and route contracts -1. Add `sessions-pr-request-schema` and `sessions-pr-response-schema` to `deps/db-sync/src/logseq/db_sync/malli_schema.cljs`. +1. Add `sessions-pr-request-schema` and `sessions-pr-response-schema` to `deps/workers/src/logseq/sync/malli_schema.cljs`. -2. Register `:sessions/pr` in `http-request-schemas` and `http-response-schemas` in `deps/db-sync/src/logseq/db_sync/malli_schema.cljs`. +2. Register `:sessions/pr` in `http-request-schemas` and `http-response-schemas` in `deps/workers/src/logseq/sync/malli_schema.cljs`. -3. Add optional capability contract fields to `sessions-create-request-schema` in `deps/db-sync/src/logseq/db_sync/malli_schema.cljs` using kebab-case keys only. +3. Add optional capability contract fields to `sessions-create-request-schema` in `deps/workers/src/logseq/sync/malli_schema.cljs` using kebab-case keys only. -4. Extend `normalize-session-create` in `deps/db-sync/src/logseq/db_sync/worker/agent/request.cljs` to persist capability profile into task payload with defaults. +4. Extend `normalize-session-create` in `deps/workers/src/logseq/agents/request.cljs` to persist capability profile into task payload with defaults. -5. Add `POST /sessions/:session-id/pr` route entry in `deps/db-sync/src/logseq/db_sync/worker/routes/index.cljs`. +5. Add `POST /sessions/:session-id/pr` route entry in `deps/workers/src/logseq/sync/worker/routes/index.cljs`. -6. Add route coverage tests for the new path in `deps/db-sync/test/logseq/db_sync/worker_routes_test.cljs`. +6. Add route coverage tests for the new path in `deps/workers/test/logseq/sync/worker_routes_test.cljs`. -7. Run `bb dev:test -v logseq.db-sync.worker-routes-test/match-route-sessions-test` and confirm the new route test fails before implementation and passes after wiring. +7. Run `bb dev:test -v logseq.sync.worker-routes-test/match-route-sessions-test` and confirm the new route test fails before implementation and passes after wiring. ### Phase 2: Agent handler forwarding -1. Add `handle-pr` request forwarding function to `deps/db-sync/src/logseq/db_sync/worker/handler/agent.cljs`. +1. Add `handle-pr` request forwarding function to `deps/workers/src/logseq/agents/handler.cljs`. -2. Reuse `base-headers` and `forward-request` in `deps/db-sync/src/logseq/db_sync/worker/handler/agent.cljs` so publish requests keep user identity headers. +2. Reuse `base-headers` and `forward-request` in `deps/workers/src/logseq/agents/handler.cljs` so publish requests keep user identity headers. -3. Add `:sessions/pr` branch in `handle` dispatch in `deps/db-sync/src/logseq/db_sync/worker/handler/agent.cljs`. +3. Add `:sessions/pr` branch in `handle` dispatch in `deps/workers/src/logseq/agents/handler.cljs`. -4. Validate and coerce publish request body with `:sessions/pr` schema before forwarding in `deps/db-sync/src/logseq/db_sync/worker/handler/agent.cljs`. +4. Validate and coerce publish request body with `:sessions/pr` schema before forwarding in `deps/workers/src/logseq/agents/handler.cljs`. 5. Add a focused handler test namespace if missing to verify `/sessions/:id/pr` forwards to `/__session__/pr`. 6. Run the focused handler test and confirm red then green behavior. ### Phase 3: Source control abstraction -1. Create `deps/db-sync/src/logseq/db_sync/worker/agent/source_control.cljs` with a minimal provider protocol for repo parsing, manual PR URL building, and PR creation. +1. Create `deps/workers/src/logseq/agents/source_control.cljs` with a minimal provider protocol for repo parsing, manual PR URL building, and PR creation. -2. Add GitHub URL parsing helpers in `deps/db-sync/src/logseq/db_sync/worker/agent/source_control.cljs` for HTTPS and SSH remote forms. +2. Add GitHub URL parsing helpers in `deps/workers/src/logseq/agents/source_control.cljs` for HTTPS and SSH remote forms. -3. Add branch-name normalization and sanitization helpers in `deps/db-sync/src/logseq/db_sync/worker/agent/source_control.cljs`. +3. Add branch-name normalization and sanitization helpers in `deps/workers/src/logseq/agents/source_control.cljs`. -4. Implement GitHub PR creation in `deps/db-sync/src/logseq/db_sync/worker/agent/source_control.cljs` using `js/fetch` and strict HTTP status handling. +4. Implement GitHub PR creation in `deps/workers/src/logseq/agents/source_control.cljs` using `js/fetch` and strict HTTP status handling. -5. Add manual PR URL fallback builder in `deps/db-sync/src/logseq/db_sync/worker/agent/source_control.cljs`. +5. Add manual PR URL fallback builder in `deps/workers/src/logseq/agents/source_control.cljs`. -6. Add source-control error classification with stable `:reason` values in `deps/db-sync/src/logseq/db_sync/worker/agent/source_control.cljs`. +6. Add source-control error classification with stable `:reason` values in `deps/workers/src/logseq/agents/source_control.cljs`. -7. Add a new test namespace `deps/db-sync/test/logseq/db_sync/agent_source_control_test.cljs` for URL parsing, branch sanitization, fallback URL generation, and API error mapping. +7. Add a new test namespace `deps/workers/test/logseq/agents/source_control_test.cljs` for URL parsing, branch sanitization, fallback URL generation, and API error mapping. -8. Run `bb dev:test -v logseq.db-sync.agent-source-control-test` and keep this test set green before moving on. +8. Run `bb dev:test -v logseq.agents.source-control-test` and keep this test set green before moving on. ### Phase 4: Runtime-provider push execution -1. Extend `RuntimeProvider` protocol in `deps/db-sync/src/logseq/db_sync/worker/agent/runtime_provider.cljs` with a push execution entrypoint. +1. Extend `RuntimeProvider` protocol in `deps/workers/src/logseq/agents/runtime_provider.cljs` with a push execution entrypoint. -2. Implement push execution for `SpritesProvider` in `deps/db-sync/src/logseq/db_sync/worker/agent/runtime_provider.cljs` by executing git commands inside the repo directory. +2. Implement push execution for `SpritesProvider` in `deps/workers/src/logseq/agents/runtime_provider.cljs` by executing git commands inside the repo directory. -3. Implement push execution for `CloudflareProvider` in `deps/db-sync/src/logseq/db_sync/worker/agent/runtime_provider.cljs` via existing sandbox exec helpers. +3. Implement push execution for `CloudflareProvider` in `deps/workers/src/logseq/agents/runtime_provider.cljs` via existing sandbox exec helpers. -4. Implement explicit unsupported behavior for `LocalDevProvider` in `deps/db-sync/src/logseq/db_sync/worker/agent/runtime_provider.cljs` with actionable error data. +4. Implement explicit unsupported behavior for `LocalDevProvider` in `deps/workers/src/logseq/agents/runtime_provider.cljs` with actionable error data. -5. Add command builders that avoid shell injection by strict branch validation in `deps/db-sync/src/logseq/db_sync/worker/agent/runtime_provider.cljs`. +5. Add command builders that avoid shell injection by strict branch validation in `deps/workers/src/logseq/agents/runtime_provider.cljs`. 6. Classify push failures into deterministic reason codes such as `auth`, `no-branch`, `no-commits`, `remote-rejected`, and `unknown`. -7. Add push-path tests in `deps/db-sync/test/logseq/db_sync/agent_runtime_provider_test.cljs` for sprites and cloudflare command composition. +7. Add push-path tests in `deps/workers/test/logseq/agents/runtime_provider_test.cljs` for sprites and cloudflare command composition. -8. Add tests that local-dev push returns a structured unsupported error in `deps/db-sync/test/logseq/db_sync/agent_runtime_provider_test.cljs`. +8. Add tests that local-dev push returns a structured unsupported error in `deps/workers/test/logseq/agents/runtime_provider_test.cljs`. -9. Run `bb dev:test -v logseq.db-sync.agent-runtime-provider-test` and verify all publish-related cases. +9. Run `bb dev:test -v logseq.agents.runtime-provider-test` and verify all publish-related cases. ### Phase 5: Session DO publish orchestration -1. Add publish request parsing and validation helpers to `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs`. +1. Add publish request parsing and validation helpers to `deps/workers/src/logseq/agents/do.cljs`. -2. Add capability guard helpers in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs` with defaults `push-enabled=true` and `pr-enabled=true`. +2. Add capability guard helpers in `deps/workers/src/logseq/agents/do.cljs` with defaults `push-enabled=true` and `pr-enabled=true`. -3. Add branch resolution helper in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs` using request head branch, runtime branch, and generated fallback. +3. Add branch resolution helper in `deps/workers/src/logseq/agents/do.cljs` using request head branch, runtime branch, and generated fallback. -4. Add `handle-pr` in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs` that requires authenticated user header and active runtime. +4. Add `handle-pr` in `deps/workers/src/logseq/agents/do.cljs` that requires authenticated user header and active runtime. -5. Emit `git.push.started` and `git.push.succeeded` or `git.push.failed` events in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs`. +5. Emit `git.push.started` and `git.push.succeeded` or `git.push.failed` events in `deps/workers/src/logseq/agents/do.cljs`. -6. Invoke runtime-provider push method from `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs` and return actionable errors. +6. Invoke runtime-provider push method from `deps/workers/src/logseq/agents/do.cljs` and return actionable errors. -7. Add optional PR path in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs` controlled by `create-pr` request flag. +7. Add optional PR path in `deps/workers/src/logseq/agents/do.cljs` controlled by `create-pr` request flag. -8. Emit `git.pr.started`, `git.pr.succeeded`, `git.pr.manual`, or `git.pr.failed` in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs`. +8. Emit `git.pr.started`, `git.pr.succeeded`, `git.pr.manual`, or `git.pr.failed` in `deps/workers/src/logseq/agents/do.cljs`. -9. Persist latest publish metadata under session state in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs` for replay and UI hydration. +9. Persist latest publish metadata under session state in `deps/workers/src/logseq/agents/do.cljs` for replay and UI hydration. -10. Add `/__session__/pr` path dispatch in `handle-fetch` in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs`. +10. Add `/__session__/pr` path dispatch in `handle-fetch` in `deps/workers/src/logseq/agents/do.cljs`. -11. Add idempotency guard using request header key if present in `deps/db-sync/src/logseq/db_sync/worker/agent/do.cljs` so retries do not duplicate PRs. +11. Add idempotency guard using request header key if present in `deps/workers/src/logseq/agents/do.cljs` so retries do not duplicate PRs. -12. Add publish behavior tests in `deps/db-sync/test/logseq/db_sync/agent_do_test.cljs` covering success, failure, manual fallback, and unauthenticated rejection. +12. Add publish behavior tests in `deps/workers/test/logseq/agents/do_test.cljs` covering success, failure, manual fallback, and unauthenticated rejection. -13. Add tests confirming no role-based gate exists for publish in `deps/db-sync/test/logseq/db_sync/agent_do_test.cljs`. +13. Add tests confirming no role-based gate exists for publish in `deps/workers/test/logseq/agents/do_test.cljs`. -14. Run `bb dev:test -v logseq.db-sync.agent-do-test` and keep publish scenarios green. +14. Run `bb dev:test -v logseq.agents.do-test` and keep publish scenarios green. ### Phase 6: Configuration and environment wiring -1. Add publish-related env keys to `deps/db-sync/src/logseq/db_sync/node/config.cljs` for SCM provider and credentials. +1. Add publish-related env keys to `deps/workers/src/logseq/sync/node/config.cljs` for SCM provider and credentials. -2. Pass these env keys into runtime Worker env in `deps/db-sync/src/logseq/db_sync/node/server.cljs`. +2. Pass these env keys into runtime Worker env in `deps/workers/src/logseq/sync/node/server.cljs`. -3. Add non-secret provider vars to `deps/db-sync/worker/wrangler.toml` as placeholders for deploy-time secret config. +3. Add non-secret provider vars to `deps/workers/worker/wrangler.toml` as placeholders for deploy-time secret config. -4. Add doc updates for required secrets and optional PR mode in `deps/db-sync/README.md`. +4. Add doc updates for required secrets and optional PR mode in `deps/workers/README.md`. 5. Confirm node adapter startup still succeeds with missing optional PR vars and returns manual fallback. @@ -256,35 +256,35 @@ This section is intentionally bite-sized so each step is a 2-5 minute action. ### Phase 8: Protocol and milestone docs 1. Add sessions publish API docs to `docs/agent-guide/db-sync/protocol.md`. -2. Update `deps/db-sync/docs/milestones/agents/14-m14-git-push-and-optional-pr.md` with implementation status and final contract. +2. Update `deps/workers/docs/milestones/agents/14-m14-git-push-and-optional-pr.md` with implementation status and final contract. -3. Add an operator runbook section in `deps/db-sync/README.md` for credential setup and common publish failures. +3. Add an operator runbook section in `deps/workers/README.md` for credential setup and common publish failures. -4. Document provider support matrix and fallback behavior in `deps/db-sync/README.md`. +4. Document provider support matrix and fallback behavior in `deps/workers/README.md`. ## Verification commands Run each command from repo root unless noted. ```bash -bb dev:test -v logseq.db-sync.worker-routes-test/match-route-sessions-test +bb dev:test -v logseq.sync.worker-routes-test/match-route-sessions-test ``` Expected output is a passing test that includes the `/sessions/:session-id/pr` route. ```bash -bb dev:test -v logseq.db-sync.agent-runtime-provider-test +bb dev:test -v logseq.agents.runtime-provider-test ``` Expected output is passing push command and provider behavior cases. ```bash -bb dev:test -v logseq.db-sync.agent-do-test +bb dev:test -v logseq.agents.do-test ``` Expected output is passing publish orchestration and event emission cases. ```bash -cd deps/db-sync && npm run test:node-adapter +cd deps/workers && npm run test:node-adapter ``` Expected output is zero failing tests and no regression in node adapter behavior. diff --git a/docs/agent-guide/db-sync/db-sync-guide.md b/docs/agent-guide/db-sync/db-sync-guide.md index 5e02463329..39f80fc375 100644 --- a/docs/agent-guide/db-sync/db-sync-guide.md +++ b/docs/agent-guide/db-sync/db-sync-guide.md @@ -8,7 +8,7 @@ This guide helps AI agents implement and review db-sync features consistently ac - Client runtime: `src/main/frontend/worker/db_sync.cljs` - Worker thread API: `src/main/frontend/worker/db_worker.cljs` - Handler entry points: `src/main/frontend/handler/db_based/db_sync.cljs` -- Server worker code: `deps/db-sync/src/logseq/db_sync/` +- Server worker code: `deps/workers/src/logseq/sync/` ## Implementation Workflow 1) **Define behavior**: state the new capability, expected inputs/outputs, and compatibility requirements. @@ -47,8 +47,8 @@ This guide helps AI agents implement and review db-sync features consistently ac ## Testing & Verification - Local dev(client+server): `bb dev:db-sync-start` runs the db-sync watcher, `wrangler dev`, and `yarn watch` with `ENABLE_DB_SYNC_LOCAL=true` - DB-sync server side unit-tests: `bb dev:db-sync-test` -- Node adapter tests: `cd deps/db-sync && npm run test:node-adapter` -- Node adapter build/run: `cd deps/db-sync && npm run build:node-adapter && npm run start:node-adapter` +- Node adapter tests: `cd deps/workers && npm run test:node-adapter` +- Node adapter build/run: `cd deps/workers && npm run build:node-adapter && npm run start:node-adapter` ## Review Checklist - Protocol versioning and error handling are consistent across client/server. diff --git a/docs/agent-guide/db-sync/fix-blocks-cycle.md b/docs/agent-guide/db-sync/fix-blocks-cycle.md index 777a6287a2..02f42ca319 100644 --- a/docs/agent-guide/db-sync/fix-blocks-cycle.md +++ b/docs/agent-guide/db-sync/fix-blocks-cycle.md @@ -1,14 +1,14 @@ This document describes the handling of cycles formed between multiple blocks in the implementation of db-sync. ## When cycles are detected -- Cycles are detected on the server when applying client tx batches in `deps/db-sync/src/logseq/db_sync/worker.cljs`. -- The server calls `logseq.db-sync.cycle/detect-cycle` which inspects updates to `:block/parent` (and other special attrs like class extends). +- Cycles are detected on the server when applying client tx batches in `deps/workers/src/logseq/sync/worker.cljs`. +- The server calls `logseq.sync.cycle/detect-cycle` which inspects updates to `:block/parent` (and other special attrs like class extends). - If applying the tx would introduce a cycle, the server rejects the batch with `{:type "tx/reject" :reason "cycle" ...}`. ## What the server returns - The reject payload includes: - `attr`: the attribute that introduced the cycle (for blocks this is `:block/parent`). - - `server-values`: a map of the affected entities to the server’s current value for `attr` (from `logseq.db-sync.cycle/server-values-for`). + - `server-values`: a map of the affected entities to the server’s current value for `attr` (from `logseq.sync.cycle/server-values-for`). - This allows the client to realign its local state to the server’s authoritative values. ## Client-side reconciliation diff --git a/docs/develop-logseq.md b/docs/develop-logseq.md index 800d0684d5..f9ebcec7af 100644 --- a/docs/develop-logseq.md +++ b/docs/develop-logseq.md @@ -128,14 +128,14 @@ The final released binaries or installers will be at `static/out/`. DB sync can be run locally in one of two ways as described in the following sections. To use a local sync approach, the app must be built with `$ENABLE_DB_SYNC_LOCAL` e.g. `ENABLE_DB_SYNC_LOCAL=true yarn watch`. For more -about db sync, see [its readme](/deps/db-sync/README.md). +about db sync, see [its readme](/deps/workers/README.md). ### DB sync Cloudflare Worker adapter Build and run a Cloudlare worker locally ```bash -cd deps/db-sync +cd deps/workers yarn install yarn release # This migration is a one time setup @@ -150,7 +150,7 @@ When testing Build and run the Node.js adapter for self-hosted DB sync. ```bash -cd deps/db-sync +cd deps/workers yarn install DB_SYNC_PORT=8787 \ COGNITO_ISSUER=https://cognito-idp.us-east-2.amazonaws.com/us-east-2_kAqZcxIeM \ diff --git a/insert-batches-test b/insert-batches-test index 98428f0c09..bb86282a26 100644 --- a/insert-batches-test +++ b/insert-batches-test @@ -4,7 +4,7 @@ $ clojure -M:test compile test [:test] Build completed. (831 files, 25 compiled, 0 warnings, 6.94s) Done in 10.38s. yarn run v1.22.22 -$ node static/tests.js -v logseq.db-sync.batch-test/rows- +$ node static/tests.js -v logseq.sync.batch-test/rows- :run-background-task :logseq.db.common.entity-plus/reset-immutable-entities-cache! :run-background-task :frontend.background-tasks/sync-to-worker-network-online-status :run-background-task :frontend.worker.embedding/subscribe-state diff --git a/package.json b/package.json index 9fe580be91..acb6789383 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "cljs:release-app": "clojure -M:cljs release app db-worker inference-worker", "cljs:release-publishing": "clojure -M:cljs release app publishing", "cljs:test": "clojure -M:test compile test", - "cljs:run-test": "node static/tests-with-dom-shim.js -r '^(?!logseq.db-sync.).*' -e fix-me", + "cljs:run-test": "node static/tests-with-dom-shim.js -r '^(?!logseq.sync.).*' -e fix-me", "cljs:test-no-worker": "clojure -M:test compile test-no-worker", "cljs:run-test-no-worker": "node static/tests-no-worker.js", "cljs:dev-release-app": "clojure -M:cljs release app db-worker inference-worker --config-merge \"{:closure-defines {frontend.config/DEV-RELEASE true}}\"", diff --git a/scripts/src/logseq/tasks/dev/db_sync.clj b/scripts/src/logseq/tasks/dev/sync.clj similarity index 88% rename from scripts/src/logseq/tasks/dev/db_sync.clj rename to scripts/src/logseq/tasks/dev/sync.clj index dbac811594..d57fa61b24 100644 --- a/scripts/src/logseq/tasks/dev/db_sync.clj +++ b/scripts/src/logseq/tasks/dev/sync.clj @@ -1,13 +1,13 @@ -(ns logseq.tasks.dev.db-sync +(ns logseq.tasks.dev.sync "Tasks for db-sync dev processes" (:require [babashka.process :refer [process]])) (def processes [{:name "db-sync-watch" - :dir "deps/db-sync" + :dir "deps/workers" :cmd "clojure -M:cljs watch db-sync"} {:name "wrangler-dev" - :dir "deps/db-sync/worker" + :dir "deps/workers/worker" :cmd "wrangler dev"} {:name "yarn-watch" :dir "." diff --git a/shadow-cljs.edn b/shadow-cljs.edn index c884c802c2..2dbd54ff48 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -187,7 +187,7 @@ :closure-defines {frontend.util/NODETEST true logseq.shui.util/NODETEST true} :devtools {:enabled false} - :build-options {:ns-exclude-regexp "^(frontend\\.worker|logseq\\.db-sync\\.worker)"} + :build-options {:ns-exclude-regexp "^(frontend\\.worker|logseq\\.sync\\.worker)"} ;; disable :static-fns to allow for with-redefs and repl development :compiler-options {:static-fns false} :main frontend.test.frontend-node-test-runner/main} diff --git a/src/main/frontend/handler/agent.cljs b/src/main/frontend/handler/agent.cljs index 0e38ce1288..43e6b882a2 100644 --- a/src/main/frontend/handler/agent.cljs +++ b/src/main/frontend/handler/agent.cljs @@ -11,7 +11,7 @@ [frontend.state :as state] [frontend.util :as util] [lambdaisland.glogi :as log] - [logseq.db-sync.malli-schema :as db-sync-schema] + [logseq.sync.malli-schema :as db-sync-schema] [promesa.core :as p])) (def ^:private invalid-coerce ::invalid-coerce) diff --git a/src/main/frontend/handler/db_based/sync.cljs b/src/main/frontend/handler/db_based/sync.cljs index 0443e72b92..4d6f5671da 100644 --- a/src/main/frontend/handler/db_based/sync.cljs +++ b/src/main/frontend/handler/db_based/sync.cljs @@ -10,8 +10,8 @@ [frontend.util :as util] [lambdaisland.glogi :as log] [logseq.db :as ldb] - [logseq.db-sync.malli-schema :as db-sync-schema] [logseq.db.sqlite.util :as sqlite-util] + [logseq.sync.malli-schema :as db-sync-schema] [promesa.core :as p])) (defn- ws->http-base [ws-url] diff --git a/src/main/frontend/worker/sync.cljs b/src/main/frontend/worker/sync.cljs index 6ffe40cbe5..7a4f5860d4 100644 --- a/src/main/frontend/worker/sync.cljs +++ b/src/main/frontend/worker/sync.cljs @@ -16,14 +16,14 @@ [lambdaisland.glogi :as log] [logseq.common.util :as common-util] [logseq.db :as ldb] - [logseq.db-sync.cycle :as sync-cycle] - [logseq.db-sync.malli-schema :as db-sync-schema] - [logseq.db-sync.order :as sync-order] [logseq.db.common.normalize :as db-normalize] [logseq.db.common.sqlite :as common-sqlite] [logseq.db.sqlite.util :as sqlite-util] [logseq.outliner.core :as outliner-core] [logseq.outliner.transaction :as outliner-tx] + [logseq.sync.cycle :as sync-cycle] + [logseq.sync.malli-schema :as db-sync-schema] + [logseq.sync.order :as sync-order] [promesa.core :as p])) (defonce *repo->latest-remote-tx (atom {})) diff --git a/src/main/frontend/worker/sync/crypt.cljs b/src/main/frontend/worker/sync/crypt.cljs index fc5b93cd6e..cc23f2779f 100644 --- a/src/main/frontend/worker/sync/crypt.cljs +++ b/src/main/frontend/worker/sync/crypt.cljs @@ -10,7 +10,7 @@ [frontend.worker.sync.const :as sync-const] [lambdaisland.glogi :as log] [logseq.db :as ldb] - [logseq.db-sync.malli-schema :as db-sync-schema] + [logseq.sync.malli-schema :as db-sync-schema] [promesa.core :as p])) (defonce ^:private *graph->aes-key (atom {})) diff --git a/src/test/frontend/worker/db_sync_sim_test.cljs b/src/test/frontend/worker/sync_sim_test.cljs similarity index 99% rename from src/test/frontend/worker/db_sync_sim_test.cljs rename to src/test/frontend/worker/sync_sim_test.cljs index 2537386120..9535a39348 100644 --- a/src/test/frontend/worker/db_sync_sim_test.cljs +++ b/src/test/frontend/worker/sync_sim_test.cljs @@ -1,4 +1,4 @@ -(ns frontend.worker.db-sync-sim-test +(ns frontend.worker.sync-sim-test (:require [cljs.test :refer [deftest is testing]] [clojure.data :as data] [datascript.core :as d] diff --git a/src/test/frontend/worker/db_sync_test.cljs b/src/test/frontend/worker/sync_test.cljs similarity index 99% rename from src/test/frontend/worker/db_sync_test.cljs rename to src/test/frontend/worker/sync_test.cljs index 268fa8685b..3f0148100a 100644 --- a/src/test/frontend/worker/db_sync_test.cljs +++ b/src/test/frontend/worker/sync_test.cljs @@ -1,4 +1,4 @@ -(ns frontend.worker.db-sync-test +(ns frontend.worker.sync-test (:require [cljs.test :refer [deftest is testing async]] [datascript.core :as d] [frontend.common.crypt :as crypt]