From cf242b778d94fd3fb85f47f5d834cf44f39130f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Sat, 28 Mar 2026 10:36:10 -0600 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 해결 #28 --- doerg/default.nix | 1 + flake.lock | 6 +- flake.nix | 2 + publisher/default.nix | 31 ++++++++- .../deertopia/publisher/default-config.edn | 2 +- .../src/net/deertopia/publisher/server.clj | 3 - publisher/test-emacs.nix | 10 +++ .../deertopia/publisher/org-roam-db-sync.el | 8 +++ .../test/net/deertopia/publisher/roam-test.db | Bin 53248 -> 0 bytes .../net/deertopia/publisher/server_test.clj | 63 ++++++++++++------ 10 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 publisher/test-emacs.nix create mode 100755 publisher/test/net/deertopia/publisher/org-roam-db-sync.el delete mode 100644 publisher/test/net/deertopia/publisher/roam-test.db diff --git a/doerg/default.nix b/doerg/default.nix index e10fdb9..fd01cb0 100644 --- a/doerg/default.nix +++ b/doerg/default.nix @@ -68,4 +68,5 @@ in mkCljBin' { checkPhase = '' clojure -M:test ''; + passthru = { inherit plex our-tex; }; } diff --git a/flake.lock b/flake.lock index a02e441..ed3496c 100644 --- a/flake.lock +++ b/flake.lock @@ -111,11 +111,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1760038930, - "narHash": "sha256-Oncbh0UmHjSlxO7ErQDM3KM0A5/Znfofj2BSzlHLeVw=", + "lastModified": 1774386573, + "narHash": "sha256-4hAV26quOxdC6iyG7kYaZcM3VOskcPUrdCQd/nx8obc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0b4defa2584313f3b781240b29d61f6f9f7e0df3", + "rev": "46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 158300b..f5be4b9 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,7 @@ default = pkgs.mkShell { inputsFrom = [ pkgs.doerg + pkgs.publisher pkgs.doerg-parser pkgs.doerg-temml-worker ]; @@ -68,6 +69,7 @@ clojure babashka sqlite-web + pkgs.publisher.test-emacs ]; }; }); diff --git a/publisher/default.nix b/publisher/default.nix index 64335c8..423e92f 100644 --- a/publisher/default.nix +++ b/publisher/default.nix @@ -1,9 +1,25 @@ { mkCljBin , doerg , babashka +, callPackage +, test-emacs ? callPackage ./test-emacs.nix {} +, fake-git +, breakpointHook +, doerg-temml-worker +, doerg-parser }: -mkCljBin { +let + # 이 mkCljBin에는 fake-git가 포함되지 않는다. 그것 불필요해서 dev + # shell에 없고 싶는다. + mkCljBin' = args: (mkCljBin args).overrideAttrs (final: prev: { + nativeBuildInputs = + builtins.filter + # A possibly-sketchy predicate, lol. + (x: x != fake-git) + prev.nativeBuildInputs; + }); +in mkCljBin' { name = "net.deertopia/publisher"; version = "0.1.0"; projectSrc = ./.; @@ -14,6 +30,15 @@ mkCljBin { ]; nativeBuildInputs = [ babashka + breakpointHook + ]; + nativeCheckInputs = [ + doerg-parser + doerg-temml-worker + test-emacs + doerg + doerg.our-tex + doerg.plex ]; postPatch = '' mv deps.edn deps.edn.old @@ -22,6 +47,10 @@ mkCljBin { ''; doCheck = true; checkPhase = '' + export \ + EMACS=test-emacs \ + XDG_STATE_HOME=$(mktemp -d "state-home-XXXXXX") clojure -M:test ''; + passthru = { inherit test-emacs; }; } diff --git a/publisher/resources/net/deertopia/publisher/default-config.edn b/publisher/resources/net/deertopia/publisher/default-config.edn index cb13ffc..85bb147 100644 --- a/publisher/resources/net/deertopia/publisher/default-config.edn +++ b/publisher/resources/net/deertopia/publisher/default-config.edn @@ -4,5 +4,5 @@ "/doerg-publisher"] :org-roam-db-path #profile {:default #join [#env HOME "/.cache/emacs/org-roam.db"] - :test #file "../../../../test/net/deertopia/publisher/roam-test.db"} + :test #join [#or [#env TMP "/tmp"] "/doerg-org-roam-test.db"]} :port #profile {:default 8080}} diff --git a/publisher/src/net/deertopia/publisher/server.clj b/publisher/src/net/deertopia/publisher/server.clj index 6d1b215..4864984 100644 --- a/publisher/src/net/deertopia/publisher/server.clj +++ b/publisher/src/net/deertopia/publisher/server.clj @@ -97,9 +97,6 @@ (assoc-in [:path-params :slug] homepage-slug) node-by-slug)) -(def doerg-resources - #{"Temml-Plex.css" "tuftesque.css" "deerstar.css"}) - (defn handle-resource [{:keys [uri]}] (if-some [[_ resource] (re-matches #"^/resource/ibm-plex-web/(.*)" uri)] (-> resource diff --git a/publisher/test-emacs.nix b/publisher/test-emacs.nix new file mode 100644 index 0000000..6bea7d8 --- /dev/null +++ b/publisher/test-emacs.nix @@ -0,0 +1,10 @@ +{ emacsPackages +, symlinkJoin +, writeScriptBin +, lib +}: + +let emacs = emacsPackages.emacsWithPackages (epkgs: [ epkgs.org-roam ]); +in writeScriptBin "test-emacs" '' + exec ${lib.getExe emacs} "$@" +'' diff --git a/publisher/test/net/deertopia/publisher/org-roam-db-sync.el b/publisher/test/net/deertopia/publisher/org-roam-db-sync.el new file mode 100755 index 0000000..0f1eaa8 --- /dev/null +++ b/publisher/test/net/deertopia/publisher/org-roam-db-sync.el @@ -0,0 +1,8 @@ +#!/usr/bin/env -S emacs -Q -x + +(require 'org-roam) + +(setq org-roam-directory (expand-file-name (car command-line-args-left))) +(setq org-roam-db-location (expand-file-name (cadr command-line-args-left))) + +(org-roam-db-sync) diff --git a/publisher/test/net/deertopia/publisher/roam-test.db b/publisher/test/net/deertopia/publisher/roam-test.db deleted file mode 100644 index 5138bb9f2189244987138fe56991976ab47e5ec1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53248 zcmWFz^vNtqRY=P(%1ta$FlG>7U}R))P*7lCU|?ooVBlpy04@dw1{MUDfsuiMK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oj4Do-5n&hC>p`R3ymM5ya5Uly2THQ zQ*p-#7ymT|CjJHn{?+^qpsY5EM?+vV1V%$(Gz3ONU^E0qLtr!nMnhmU1V%$(Gz3ON zU^E1%9|Bs;k&MI*f-r-X5;Y12T0B7Hsd}LKe+B{S`)kz1(GVC7fzc2c4S~@R7!85Z z5Eu=C(GVC7fzc2c4S~@R7!85J69S|C|G^U%qb?Z@fzc2c4S~@R7!85Z5Eu=C(GVC7 zfzc2c4S~@R7!3hhg}`Y4pH?9|YVK$VjE2By2#kinXb6mkz-S1JhQMeDjE2By2#kin zXb23R5E$+M51zOfb;)Q5jE2By2#kinXb6mkz-S1JhQMeDjE2By2#kinXb8|M1V;P+ zv> [(System/getenv "EMACS") "test-emacs" "emacs"] + (some #(some-> % fs/which)))] + (io/copy (-> "net/deertopia/publisher/org-roam-db-sync.el" + io/resource io/reader) + (fs/file script-file)) + (p/shell {:out :string :err :string} + emacs "-Q" "-x" script-file org-roam-directory db-file) + (fs/delete script-file))) + +(defn test-db-fixture [f] + (let [db-file (-> publisher-cfg/*cfg* ::publisher/org-roam-db-path)] + (fs/delete-if-exists db-file) + (org-roam-db-sync db-file) + (f) + (fs/delete db-file))) + (t/use-fixtures - :once config-fixture) + :once (t/join-fixtures [config-fixture test-db-fixture])) (defn with-server [f] (let [was-already-running? (= :running (sut/status))] @@ -34,6 +59,8 @@ (sut/app {:request-method :get :uri uri})) + + (t/deftest server-is-running ;; 서버는 벌써 시작한 다음에 이 테스트 하면 잘못됩니다. ;; (assert (not= :running (sut/status))) @@ -41,25 +68,23 @@ (fn [] (t/is (= :running (sut/status))) ;; 테스트 데이터베이스를 아직 안 준비한다. - #_(t/is (->> (format "http://localhost:%d" + (t/is (->> (format "http://localhost:%d" (::publisher/port publisher-cfg/*cfg*)) slurp string?))))) -(comment - ;; 테스트 데이터베이스를 아직 안 준비한다. - (t/deftest get-nonexistent-node - (let [slug "3Lxvxnb0QrivoU3DX-l_5w"] - (assert (nil? (roam/make-node slug))) - (t/is (= 404 - (-> (str "/n/" slug) - get-sut :status)))))) +;; 테스트 데이터베이스를 아직 안 준비한다. +(t/deftest get-nonexistent-node + (let [slug "3Lxvxnb0QrivoU3DX-l_5w"] + (assert (nil? (roam/make-node slug))) + (t/is (= 404 + (-> (str "/n/" slug) + get-sut :status))))) -(comment - ;; 테스트 데이터베이스를 아직 안 준비한다. - (t/deftest get-homepage - (let [resp (-> (str "/n/" sut/homepage-slug) - get-sut)] - (t/is (= 200 (:status resp))) - (t/is (= (-> "/" get-sut :body) - (-> resp :body)))))) +;; 테스트 데이터베이스를 아직 안 준비한다. +(t/deftest get-homepage + (let [resp (-> (str "/n/" sut/homepage-slug) + get-sut)] + (t/is (= 200 (:status resp))) + (t/is (= (-> "/" get-sut :body) + (-> resp :body)))))