From 1d5a7bad80eb1a02c267864642b7d0209728b952 Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 11 Mar 2026 02:02:46 -0300 Subject: [PATCH 01/44] Drop 'latest' tag as a way of finding the newest tag --- .justfile | 32 ++++++-------------------------- containers/Containerfile.alpine | 17 +++++++++++++++-- containers/Containerfile.debian | 17 +++++++++++++++-- static/graph.toml | 2 +- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/.justfile b/.justfile index ee8ceac..f03aae8 100644 --- a/.justfile +++ b/.justfile @@ -165,22 +165,16 @@ alias oo := cover-open # Tag HEAD with version from Cargo.toml [script, group: 'assess'] -tag: update +tag commit="HEAD": update if [ "{{ last_tag }}" = "{{ manifest_version }}" ]; then echo "Last tag {{ last_tag }} and manifest ({{ manifest_version }}) already match" - if [ "{{ last_tag }}" != "{{ tagged_latest }}" ]; then - echo "Last tag {{ last_tag }} and 'latest' tag ({{ tagged_latest }}) diverge" - git tag --force latest "v{{ manifest_version }}" - {{ just_cmd }} version-assess - fi exit elif [ "{{ manifest_version }}" != "{{ lockfile_version }}" ]; then echo "Manifest and lockfile versions don't match: update failed?" exit 1 fi - git tag "v{{ manifest_version }}" HEAD - git tag --force latest "v{{ manifest_version }}" + git tag "v{{ manifest_version }}" {{ commit }} {{ just_cmd }} version-assess # Verify and push @@ -191,13 +185,6 @@ push: verify alias p := push -# Push tag 'latest' -[group: 'develop'] -push-tag-latest-unsafe: - git push origin tag latest --force --no-verify - -alias ptlu := push-tag-latest-unsafe - # Push without verifying [group: 'develop'] push-unsafe: @@ -306,15 +293,13 @@ alias v := verify [script, group: 'assess'] version-assess: update if - [ "{{ last_tag }}" != "{{ tagged_latest }}" ] \ - || [ "{{ last_tag }}" != "{{ lockfile_version }}" ] \ + [ "{{ last_tag }}" != "{{ lockfile_version }}" ] \ || [ "{{ last_tag }}" != "{{ lockfile_version }}" ] then - printf 'Last tag: %s\nManifest: %s\nLockfile: %s\nTagged latest: %s\n' \ + printf 'Last tag: %s\nManifest: %s\nLockfile: %s\n' \ "{{ last_tag }}" \ "{{ manifest_version }}" \ - "{{ lockfile_version }}" \ - "{{ tagged_latest }}" + "{{ lockfile_version }}" exit 1 fi @@ -413,12 +398,7 @@ watch_cmd := "watchexec -qc -r -e rs,toml,html --color always -- " cover_cmd := 'cargo llvm-cov --color always --ignore-filename-regex "main\.rs|log\.rs"' just_cmd := 'just --timestamp --explain --command-color green' -last_tag := ``` - git tag --sort=-creatordate \ - | grep -v '^latest$' | head -1 | tr -d v - ``` -tagged_latest := `git tag --points-at $(git rev-parse latest) \ - | grep -v '^latest$' | tr -d v` +last_tag := `git tag --sort=-creatordate | head -1 | tr -d v` manifest_version := `grep "^version" Cargo.toml | cut -d \" -f 2` lockfile_version := ``` grep -A 1 'name = "en"' Cargo.lock \ diff --git a/containers/Containerfile.alpine b/containers/Containerfile.alpine index 784f3c3..392d605 100644 --- a/containers/Containerfile.alpine +++ b/containers/Containerfile.alpine @@ -1,14 +1,27 @@ FROM alpine:latest MAINTAINER Juno Takano juno@jutty.dev ENV DEBUG=debug -ENV TAG=${TAG:-latest} # Setup tooling RUN apk add curl clang git file RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y # Install -RUN git clone -b "$TAG" --single-branch https://codeberg.org/jutty/en /build +RUN < Date: Wed, 11 Mar 2026 02:32:19 -0300 Subject: [PATCH 02/44] Strip header from canonical licenses --- src/router/handlers/fixed.rs | 6 +- static/public/assets/fonts/LICENSES.sha256sum | 22 +- .../CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE | 392 ++++++++++++++++++ .../fonts/_canon/SIL_OFL_1_1.body.LICENSE | 85 ++++ .../assets/fonts/reforma/header.LICENSE | 1 - static/public/assets/fonts/split.sh | 74 +++- 6 files changed, 548 insertions(+), 32 deletions(-) create mode 100644 static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE create mode 100644 static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE diff --git a/src/router/handlers/fixed.rs b/src/router/handlers/fixed.rs index 57672e2..c274dc7 100644 --- a/src/router/handlers/fixed.rs +++ b/src/router/handlers/fixed.rs @@ -390,8 +390,6 @@ static TEXTS: &[(&str, &str)] = &[ "assets/favicon.svg", include_str!("../../../static/public/assets/favicon.svg"), ), - ("assets/licenses/SIL_OFL_1_1.txt", OFL.text), - ("assets/licenses/CC_BY_ND_4_0_INTERNATIONAL.txt", CCND.text), ]; pub static FONTS: &[(&str, &Font)] = &[ @@ -611,7 +609,7 @@ static OFL: License = License { kind: &LicenseKind::SIL_OFL_1_1, url: "assets/licenses/SIL_OFL_1_1.txt", text: include_str!( - "../../../static/public/assets/fonts/_canon/SIL_OFL_1_1.LICENSE" + "../../../static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE" ), }; @@ -621,7 +619,7 @@ static CCND: License = License { url: "/assets/licenses/CC_BY_ND_4_0_INTERNATIONAL.txt", text: include_str!( "../../../static/public/assets/fonts/_canon/\ - CC_BY_ND_4_0_INTERNATIONAL.LICENSE" + CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE" ), }; diff --git a/static/public/assets/fonts/LICENSES.sha256sum b/static/public/assets/fonts/LICENSES.sha256sum index 4cf7352..b2023fc 100644 --- a/static/public/assets/fonts/LICENSES.sha256sum +++ b/static/public/assets/fonts/LICENSES.sha256sum @@ -1,19 +1,21 @@ -9cc97638cf0185884ac800144b6246c7772f94ff2cc70686afa9574aaea4fa2b ./_licenses/CC_BY_ND_4_0_INTERNATIONAL.LICENSE -8a0b028b517cc55196eb9d8b52be9af6681a012fea18b1f66fb54e8d98f5689b ./_licenses/CC_BY_ND_4_0_INTERNATIONAL.compact.LICENSE -1d361a8f8e8ce6e68457dcd93fb56e162e6baa3bbb7e7573a290d44399f6b57e ./_licenses/SIL_OFL_1_1.LICENSE -b9b403f45aa19c80648bfc7164caf8bf0b38727d7ea31d8bbc8ec850a8646237 ./_licenses/SIL_OFL_1_1.compact.LICENSE +9cc97638cf0185884ac800144b6246c7772f94ff2cc70686afa9574aaea4fa2b ./_canon/CC_BY_ND_4_0_INTERNATIONAL.LICENSE +00b6b2ffad0a8a99a0497b6474d16296adb91a9d9d83dd745d3148176aa16b7e ./_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE +5f1cc99e4d0fe6ed3495b8f7fb57bdd07623b99a9f0b2bde6076ef3719f162f9 ./_canon/CC_BY_ND_4_0_INTERNATIONAL.compact.LICENSE +1d361a8f8e8ce6e68457dcd93fb56e162e6baa3bbb7e7573a290d44399f6b57e ./_canon/SIL_OFL_1_1.LICENSE +6863ff4dc820f24756b6acfb38a2c6bc19d5b8d71b17030330a6f16eb4cee348 ./_canon/SIL_OFL_1_1.body.LICENSE +2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./_canon/SIL_OFL_1_1.compact.LICENSE 3f70f82d58c8f58b91cf8d718621ac1537234eb6f37ee9a83469a321ef46e4db ./cormorant/LICENSE -b9b403f45aa19c80648bfc7164caf8bf0b38727d7ea31d8bbc8ec850a8646237 ./cormorant/compact.LICENSE +2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./cormorant/compact.LICENSE c110f34253aced57d6d4f02edce58b171dca3340591a1119e02ea084a4b78f93 ./cormorant/header.LICENSE 7d5da66dc426b59bbba125049b7016f2011f93724ddf7b7f97ce1911f958b963 ./maven/LICENSE -b9b403f45aa19c80648bfc7164caf8bf0b38727d7ea31d8bbc8ec850a8646237 ./maven/compact.LICENSE +2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./maven/compact.LICENSE c63dd928ccd5c2c80491b84d1874227536dfced1f1f82cbd900ddc86c59b738b ./maven/header.LICENSE 1d2892790cc9522de02d3f01ba48d12742862b1a69d04d69752938591efabecd ./mononoki/LICENSE -b9b403f45aa19c80648bfc7164caf8bf0b38727d7ea31d8bbc8ec850a8646237 ./mononoki/compact.LICENSE +2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./mononoki/compact.LICENSE 20601bbaafe0fe8d6a39527785fc501f242ebae18d1aaa4d5d15a8ac4ff4fff3 ./mononoki/header.LICENSE 3e57bc17e8ece63050a2ac5aa99a80f87183289b18303d46311199875b4808b7 ./rawengulk/LICENSE -b9b403f45aa19c80648bfc7164caf8bf0b38727d7ea31d8bbc8ec850a8646237 ./rawengulk/compact.LICENSE +2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./rawengulk/compact.LICENSE 4d8b5ec962dfeb2813bdeb0762e3b714e68e19f9fbcdb3481d12f018b125308b ./rawengulk/header.LICENSE 18837f5b671bd48dc6b595a475d8c45ab3e6ae33adb65d9bbeac59c58f77bc24 ./reforma/LICENSE -71a379fe7cce14275bab647c25fe024c085d9618c836c476338ef88d33e38b22 ./reforma/compact.LICENSE -c870d796e9bad6ab1b29bb73ea3ef316355d24d8efad78272636aaf95033ae9a ./reforma/header.LICENSE +2edceb2f872692052b281629777bc5af5386601dd4c437f297f84846f9fa75cf ./reforma/compact.LICENSE +a3d29ef378426d0b1d9f17364a3d7532ad623a51c8c19a3badc74c23e5e93ef6 ./reforma/header.LICENSE diff --git a/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE new file mode 100644 index 0000000..6c5a1fe --- /dev/null +++ b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE @@ -0,0 +1,392 @@ +Attribution-NoDerivatives 4.0 International + +======================================================================= + +Creative Commons Corporation ("Creative Commons") is not a law firm and +does not provide legal services or legal advice. Distribution of +Creative Commons public licenses does not create a lawyer-client or +other relationship. Creative Commons makes its licenses and related +information available on an "as-is" basis. Creative Commons gives no +warranties regarding its licenses, any material licensed under their +terms and conditions, or any related information. Creative Commons +disclaims all liability for damages resulting from their use to the +fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and +conditions that creators and other rights holders may use to share +original works of authorship and other material subject to copyright +and certain other rights specified in the public license below. The +following considerations are for informational purposes only, are not +exhaustive, and do not form part of our licenses. + + Considerations for licensors: Our public licenses are + intended for use by those authorized to give the public + permission to use material in ways otherwise restricted by + copyright and certain other rights. Our licenses are + irrevocable. Licensors should read and understand the terms + and conditions of the license they choose before applying it. + Licensors should also secure all rights necessary before + applying our licenses so that the public can reuse the + material as expected. Licensors should clearly mark any + material not subject to the license. This includes other CC- + licensed material, or material used under an exception or + limitation to copyright. More considerations for licensors: + wiki.creativecommons.org/Considerations_for_licensors + + Considerations for the public: By using one of our public + licenses, a licensor grants the public permission to use the + licensed material under specified terms and conditions. If + the licensor's permission is not necessary for any reason--for + example, because of any applicable exception or limitation to + copyright--then that use is not regulated by the license. Our + licenses grant only permissions under copyright and certain + other rights that a licensor has authority to grant. Use of + the licensed material may still be restricted for other + reasons, including because others have copyright or other + rights in the material. A licensor may make special requests, + such as asking that all changes be marked or described. + Although not required by our licenses, you are encouraged to + respect those requests where reasonable. More considerations + for the public: + wiki.creativecommons.org/Considerations_for_licensees + + +======================================================================= + +Creative Commons Attribution-NoDerivatives 4.0 International Public +License + +By exercising the Licensed Rights (defined below), You accept and agree +to be bound by the terms and conditions of this Creative Commons +Attribution-NoDerivatives 4.0 International Public License ("Public +License"). To the extent this Public License may be interpreted as a +contract, You are granted the Licensed Rights in consideration of Your +acceptance of these terms and conditions, and the Licensor grants You +such rights in consideration of benefits the Licensor receives from +making the Licensed Material available under these terms and +conditions. + + +Section 1 -- Definitions. + + a. Adapted Material means material subject to Copyright and Similar + Rights that is derived from or based upon the Licensed Material + and in which the Licensed Material is translated, altered, + arranged, transformed, or otherwise modified in a manner requiring + permission under the Copyright and Similar Rights held by the + Licensor. For purposes of this Public License, where the Licensed + Material is a musical work, performance, or sound recording, + Adapted Material is always produced where the Licensed Material is + synched in timed relation with a moving image. + + b. Copyright and Similar Rights means copyright and/or similar rights + closely related to copyright including, without limitation, + performance, broadcast, sound recording, and Sui Generis Database + Rights, without regard to how the rights are labeled or + categorized. For purposes of this Public License, the rights + specified in Section 2(b)(1)-(2) are not Copyright and Similar + Rights. + + c. Effective Technological Measures means those measures that, in the + absence of proper authority, may not be circumvented under laws + fulfilling obligations under Article 11 of the WIPO Copyright + Treaty adopted on December 20, 1996, and/or similar international + agreements. + + d. Exceptions and Limitations means fair use, fair dealing, and/or + any other exception or limitation to Copyright and Similar Rights + that applies to Your use of the Licensed Material. + + e. Licensed Material means the artistic or literary work, database, + or other material to which the Licensor applied this Public + License. + + f. Licensed Rights means the rights granted to You subject to the + terms and conditions of this Public License, which are limited to + all Copyright and Similar Rights that apply to Your use of the + Licensed Material and that the Licensor has authority to license. + + g. Licensor means the individual(s) or entity(ies) granting rights + under this Public License. + + h. Share means to provide material to the public by any means or + process that requires permission under the Licensed Rights, such + as reproduction, public display, public performance, distribution, + dissemination, communication, or importation, and to make material + available to the public including in ways that members of the + public may access the material from a place and at a time + individually chosen by them. + + i. Sui Generis Database Rights means rights other than copyright + resulting from Directive 96/9/EC of the European Parliament and of + the Council of 11 March 1996 on the legal protection of databases, + as amended and/or succeeded, as well as other essentially + equivalent rights anywhere in the world. + + j. You means the individual or entity exercising the Licensed Rights + under this Public License. Your has a corresponding meaning. + + +Section 2 -- Scope. + + a. License grant. + + 1. Subject to the terms and conditions of this Public License, + the Licensor hereby grants You a worldwide, royalty-free, + non-sublicensable, non-exclusive, irrevocable license to + exercise the Licensed Rights in the Licensed Material to: + + a. reproduce and Share the Licensed Material, in whole or + in part; and + + b. produce and reproduce, but not Share, Adapted Material. + + 2. Exceptions and Limitations. For the avoidance of doubt, where + Exceptions and Limitations apply to Your use, this Public + License does not apply, and You do not need to comply with + its terms and conditions. + + 3. Term. The term of this Public License is specified in Section + 6(a). + + 4. Media and formats; technical modifications allowed. The + Licensor authorizes You to exercise the Licensed Rights in + all media and formats whether now known or hereafter created, + and to make technical modifications necessary to do so. The + Licensor waives and/or agrees not to assert any right or + authority to forbid You from making technical modifications + necessary to exercise the Licensed Rights, including + technical modifications necessary to circumvent Effective + Technological Measures. For purposes of this Public License, + simply making modifications authorized by this Section 2(a) + (4) never produces Adapted Material. + + 5. Downstream recipients. + + a. Offer from the Licensor -- Licensed Material. Every + recipient of the Licensed Material automatically + receives an offer from the Licensor to exercise the + Licensed Rights under the terms and conditions of this + Public License. + + b. No downstream restrictions. You may not offer or impose + any additional or different terms or conditions on, or + apply any Effective Technological Measures to, the + Licensed Material if doing so restricts exercise of the + Licensed Rights by any recipient of the Licensed + Material. + + 6. No endorsement. Nothing in this Public License constitutes or + may be construed as permission to assert or imply that You + are, or that Your use of the Licensed Material is, connected + with, or sponsored, endorsed, or granted official status by, + the Licensor or others designated to receive attribution as + provided in Section 3(a)(1)(A)(i). + + b. Other rights. + + 1. Moral rights, such as the right of integrity, are not + licensed under this Public License, nor are publicity, + privacy, and/or other similar personality rights; however, to + the extent possible, the Licensor waives and/or agrees not to + assert any such rights held by the Licensor to the limited + extent necessary to allow You to exercise the Licensed + Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this + Public License. + + 3. To the extent possible, the Licensor waives any right to + collect royalties from You for the exercise of the Licensed + Rights, whether directly or through a collecting society + under any voluntary or waivable statutory or compulsory + licensing scheme. In all other cases the Licensor expressly + reserves any right to collect such royalties. + + +Section 3 -- License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the +following conditions. + + a. Attribution. + + 1. If You Share the Licensed Material, You must: + + a. retain the following if it is supplied by the Licensor + with the Licensed Material: + + i. identification of the creator(s) of the Licensed + Material and any others designated to receive + attribution, in any reasonable manner requested by + the Licensor (including by pseudonym if + designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of + warranties; + + v. a URI or hyperlink to the Licensed Material to the + extent reasonably practicable; + + b. indicate if You modified the Licensed Material and + retain an indication of any previous modifications; and + + c. indicate the Licensed Material is licensed under this + Public License, and include the text of, or the URI or + hyperlink to, this Public License. + + For the avoidance of doubt, You do not have permission under + this Public License to Share Adapted Material. + + 2. You may satisfy the conditions in Section 3(a)(1) in any + reasonable manner based on the medium, means, and context in + which You Share the Licensed Material. For example, it may be + reasonable to satisfy the conditions by providing a URI or + hyperlink to a resource that includes the required + information. + + 3. If requested by the Licensor, You must remove any of the + information required by Section 3(a)(1)(A) to the extent + reasonably practicable. + + +Section 4 -- Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that +apply to Your use of the Licensed Material: + + a. for the avoidance of doubt, Section 2(a)(1) grants You the right + to extract, reuse, reproduce, and Share all or a substantial + portion of the contents of the database, provided You do not Share + Adapted Material; + + b. if You include all or a substantial portion of the database + contents in a database in which You have Sui Generis Database + Rights, then the database in which You have Sui Generis Database + Rights (but not its individual contents) is Adapted Material; and + + c. You must comply with the conditions in Section 3(a) if You Share + all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not +replace Your obligations under this Public License where the Licensed +Rights include other Copyright and Similar Rights. + + +Section 5 -- Disclaimer of Warranties and Limitation of Liability. + + a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE + EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS + AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF + ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, + IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, + WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, + ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT + KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT + ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. + + b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE + TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, + NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, + INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, + COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR + USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR + DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR + IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. + + c. The disclaimer of warranties and limitation of liability provided + above shall be interpreted in a manner that, to the extent + possible, most closely approximates an absolute disclaimer and + waiver of all liability. + + +Section 6 -- Term and Termination. + + a. This Public License applies for the term of the Copyright and + Similar Rights licensed here. However, if You fail to comply with + this Public License, then Your rights under this Public License + terminate automatically. + + b. Where Your right to use the Licensed Material has terminated under + Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided + it is cured within 30 days of Your discovery of the + violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any + right the Licensor may have to seek remedies for Your violations + of this Public License. + + c. For the avoidance of doubt, the Licensor may also offer the + Licensed Material under separate terms or conditions or stop + distributing the Licensed Material at any time; however, doing so + will not terminate this Public License. + + d. Sections 1, 5, 6, 7, and 8 survive termination of this Public + License. + + +Section 7 -- Other Terms and Conditions. + + a. The Licensor shall not be bound by any additional or different + terms or conditions communicated by You unless expressly agreed. + + b. Any arrangements, understandings, or agreements regarding the + Licensed Material not stated herein are separate from and + independent of the terms and conditions of this Public License. + + +Section 8 -- Interpretation. + + a. For the avoidance of doubt, this Public License does not, and + shall not be interpreted to, reduce, limit, restrict, or impose + conditions on any use of the Licensed Material that could lawfully + be made without permission under this Public License. + + b. To the extent possible, if any provision of this Public License is + deemed unenforceable, it shall be automatically reformed to the + minimum extent necessary to make it enforceable. If the provision + cannot be reformed, it shall be severed from this Public License + without affecting the enforceability of the remaining terms and + conditions. + + c. No term or condition of this Public License will be waived and no + failure to comply consented to unless expressly agreed to by the + Licensor. + + d. Nothing in this Public License constitutes or may be interpreted + as a limitation upon, or waiver of, any privileges and immunities + that apply to the Licensor or You, including from the legal + processes of any jurisdiction or authority. + +======================================================================= + +Creative Commons is not a party to its public +licenses. Notwithstanding, Creative Commons may elect to apply one of +its public licenses to material it publishes and in those instances +will be considered the “Licensor.” The text of the Creative Commons +public licenses is dedicated to the public domain under the CC0 Public +Domain Dedication. Except for the limited purpose of indicating that +material is shared under a Creative Commons public license or as +otherwise permitted by the Creative Commons policies published at +creativecommons.org/policies, Creative Commons does not authorize the +use of the trademark "Creative Commons" or any other trademark or logo +of Creative Commons without its prior written consent including, +without limitation, in connection with any unauthorized modifications +to any of its public licenses or any other arrangements, +understandings, or agreements concerning use of licensed material. For +the avoidance of doubt, this paragraph does not form part of the +public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE b/static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE new file mode 100644 index 0000000..6e85af4 --- /dev/null +++ b/static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE @@ -0,0 +1,85 @@ +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/static/public/assets/fonts/reforma/header.LICENSE b/static/public/assets/fonts/reforma/header.LICENSE index 36ff711..8521b49 100644 --- a/static/public/assets/fonts/reforma/header.LICENSE +++ b/static/public/assets/fonts/reforma/header.LICENSE @@ -4,4 +4,3 @@ http://pampatype.com. This Font Software is licensed under the Creative Commons BY-ND 4.0. This full license is available at: https://creativecommons.org/licenses/by-nd/4.0/ ## creative commons - diff --git a/static/public/assets/fonts/split.sh b/static/public/assets/fonts/split.sh index a683c33..75829d3 100755 --- a/static/public/assets/fonts/split.sh +++ b/static/public/assets/fonts/split.sh @@ -2,6 +2,10 @@ set -eu +log() { + printf ' [split] %s\n' "$@" >&2 +} + get_marker() { # extended regex syntax cc_marker='^\#? ?Attribution-NoDerivatives 4.0 International$' @@ -14,7 +18,7 @@ get_marker() { elif grep -Eq "$cc_marker" "$m_file"; then printf '%s' "$cc_marker" else - printf '%s %s\n' "$m_file" "matches no marker" >&2 + log "$m_file matches no marker" printf '' fi } @@ -22,9 +26,25 @@ get_marker() { behead() { b_file="$1" b_marker="$2" - b_out_path="$3" + b_head_out_path="$3" + b_body_out_path="$4" + + log "Beheading $b_file on marker $b_marker" + b_body=$(sed -En "/$b_marker/, \$p" "$b_file") + b_head=$(sed -E "/$b_marker/, \$d" "$b_file") + + if [ -n "$b_head_out_path" ]; then + log "Keeping head of $b_file on $b_head_out_path" + printf '%s\n' "$b_head" \ + | sed -E 's/^-+$//' \ + > "$b_head_out_path" + fi + + if [ -n "$b_body_out_path" ]; then + log "Keeping body of $b_file on $b_body_out_path" + printf '%s\n' "$b_body" > "$b_body_out_path" + fi - sed -E "/$b_marker/, \$d" "$b_file" | sed -E 's/^-+$//' > "$b_out_path" } compact() { @@ -32,39 +52,49 @@ compact() { c_marker="$2" c_out_path="$3" - # Eliminating [:space:] is enough for OFL to match, but Reforma's - # markdown license file is full of quirks so we must reduce aggresively sed -En "/$c_marker/, \$p" "$c_file" \ - | sed -E 's/(wiki\.creativecommons\.org|https?).*\s//g' \ - | tr -cd '[:alnum:]' \ - | tr '[:upper:]' '[:lower:]' > "$c_out_path" + | tr -d '[:space:]' \ + > "$c_out_path" } +log "Iterating over font directories" for dir in *; do [ -d "$dir" ] || continue - [ "$dir" != _licenses ] || continue + [ "$dir" != _canon ] || continue license="$dir/LICENSE"; [ -f "$license" ] + log "On license $license" + marker=$(get_marker "$license") + log "Got '$marker' marker for license $license" if [ -n "$marker" ]; then - behead "$license" "$marker" "$dir/header.LICENSE" + behead "$license" "$marker" "$dir/header.LICENSE" "" compact "$license" "$marker" "$dir/compact.LICENSE" fi done -for license in _licenses/*.LICENSE; do - printf '%s' "$license" | grep -qEv '(header|compact)\.LICENSE' || continue +log "Iterating over canonical licenses" +for license in _canon/*.LICENSE; do + printf '%s' "$license" \ + | grep -qEv '(header|compact|body)\.LICENSE' \ + || continue marker=$(get_marker "$license") + log "Got '$marker' marker for license $license" + + body_name=$(printf '%s' "$license" | sed "s*\.LICENSE*.body.LICENSE*") compact_name=$(printf '%s' "$license" | sed "s*\.LICENSE*.compact.LICENSE*") + log "Using names $body_name (body) and $compact_name (compact)" + + behead "$license" "$marker" "" "$body_name" compact "$license" "$marker" "$compact_name" done for file in ./*/*LICENSE*; do size=$(du "$file" | awk '{print $1}') if [ "$size" -le 0 ]; then - echo "$file is empty" + log "$file is empty" exit 1 fi done @@ -73,15 +103,25 @@ sha256sum ./*/*LICENSE* > LICENSES.sha256sum grep compact LICENSES.sha256sum | sort unique_licenses=$( - find _licenses/ -name '*.LICENSE' -not -name '*.compact.LICENSE' | wc -l + find _canon/ \ + -name '*.LICENSE' \ + -not -name '*.compact.LICENSE' \ + -not -name '*.body.LICENSE' \ + | wc -l ) unique_hashes=$( - cat LICENSES.sha256sum | grep compact | awk '{print $1}' | sort | uniq | wc -l + cat LICENSES.sha256sum \ + | grep compact \ + | awk '{print $1}' \ + | sort \ + | uniq \ + | wc -l ) if [ "$unique_hashes" -ne "$unique_licenses" ]; then - echo "unique hashes: $unique_hashes" - echo "unique licenses: $unique_licenses" + log "Number of distinct hashes and licenses don't match." + log "unique hashes: $unique_hashes" + log "unique licenses: $unique_licenses" exit 1 fi From b806d844519a2213e6029ba7ff165da830f3d4a2 Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 11 Mar 2026 03:57:26 -0300 Subject: [PATCH 03/44] Add template and asset fallback tests --- .justfile | 5 +- src/router/handlers/template.rs | 85 +++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/.justfile b/.justfile index f03aae8..4dc2004 100644 --- a/.justfile +++ b/.justfile @@ -352,20 +352,21 @@ alias bm := build-musl [group: 'build'] release-build target=default_target: cargo build --target {{ target }} --locked --release + du -h target/{{ target }}/release/en alias rb := release-build # glibc release build [group: 'build'] release-build-gnu: - cargo build --target {{ glibc_target }} --locked --release + {{ just_cmd }} release-build {{ glibc_target }} alias rbg := release-build-gnu # musl release build [group: 'build'] release-build-musl: - cargo build --target {{ musl_target }} --locked --release + {{ just_cmd }} release-build {{ musl_target }} alias rbm := release-build-musl diff --git a/src/router/handlers/template.rs b/src/router/handlers/template.rs index 1619e14..01bb7ea 100644 --- a/src/router/handlers/template.rs +++ b/src/router/handlers/template.rs @@ -432,4 +432,89 @@ mod tests { assert_eq!(&contents, map_contents); } } + + #[test] + fn rendering_error_html_contains_inner_error() { + let outer_payload = "Gl0c7CyArjlG1Zgvj3D5BFmZT6zRz5Ky"; + let inner_payload = "t53pvXCf0JqUzwiM5BZbYxAQadYSJ9XW"; + let inner_error = tera::Error::msg(inner_payload); + let error = RenderingError::new(outer_payload, 501, &inner_error); + assert!(error.template.html.contains(inner_payload)); + assert!(error.template.html.contains(outer_payload)); + } + + #[test] + fn rendering_error_display() { + let payload = "4LKNOSqfW0Ys3LALDAond8IIp5RgN7vK"; + let error = RenderingError::new(payload, 501, &tera::Error::msg("")); + let display_string = format!("{error}"); + assert!(display_string.contains(payload)); + } + + #[test] + fn empty_template_read_is_an_error() { + let result = read_template("", PathBuf::from("")); + assert!(result.is_err()); + } + + #[test] + fn template_read_without_permissions_is_an_error() { + let result = read_template("", PathBuf::from("/etc/shadow")); + assert!(result.is_err()); + } + + #[test] + fn template_read_without_a_default_is_an_error() { + let result = read_template( + "xkQwFZpqf5iz", + PathBuf::from("templates/Boy5CZQUk2oX"), + ); + assert!(result.is_err()); + } + + #[test] + fn template_read_with_a_default_is_ok() { + let result = + read_template("base.html", PathBuf::from("templates/St1iFgeOrhCK")); + assert!(result.is_ok()); + } + + #[test] + fn template_read_with_a_file_is_ok() { + let result = + read_template("GpzjjAPhCTIr", PathBuf::from("templates/base.html")); + assert!(result.is_ok()); + } +} + +#[cfg(test)] +mod serial_tests { + use super::*; + + #[cfg_attr(not(unix), ignore)] + #[test] + fn invalid_utf8_template_filename() { + use std::{ffi::OsStr, os::unix::ffi::OsStrExt as _, path::PathBuf}; + + let original_working_directory = std::env::current_dir().unwrap(); + let base_dir = PathBuf::from("tests/mocks/encoding/temp"); + let templates_dir = base_dir.clone().join("templates"); + assert!(std::fs::create_dir_all(&base_dir).is_ok()); + assert!( + std::env::set_current_dir(&base_dir) + .is_ok() + ); + assert!(std::fs::create_dir_all(&templates_dir).is_ok()); + + + let invalid_name = OsStr::from_bytes(&[0xff, 0xfe, 0x00]); + let file_path = templates_dir.join(invalid_name); + assert!(std::fs::write(&file_path, b"eNJq4FPUqSKoozdg").is_ok()); + + let result = load_templates(); + assert!(result.is_err()); + + assert!(std::fs::remove_dir_all(&base_dir).is_ok()); + assert!(std::env::set_current_dir(original_working_directory).is_ok()); + } } From 9ebd91a5894a40ee566ca08efcd20bde6aff268f Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 16 Mar 2026 20:02:03 -0300 Subject: [PATCH 04/44] Move log module to dev::log --- src/dev.rs | 2 ++ src/{ => dev}/log.rs | 12 ++++++------ src/{ => dev}/log/level.rs | 0 src/lib.rs | 7 +++---- src/main.rs | 2 +- src/router/handlers/template.rs | 8 ++++++++ src/syntax/content/parser/lexeme.rs | 2 +- src/syntax/content/parser/token/anchor.rs | 2 +- src/syntax/content/parser/token/literal.rs | 2 +- 9 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 src/dev.rs rename src/{ => dev}/log.rs (95%) rename src/{ => dev}/log/level.rs (100%) diff --git a/src/dev.rs b/src/dev.rs new file mode 100644 index 0000000..c4eb55e --- /dev/null +++ b/src/dev.rs @@ -0,0 +1,2 @@ +pub mod log; +pub mod test; diff --git a/src/log.rs b/src/dev/log.rs similarity index 95% rename from src/log.rs rename to src/dev/log.rs index ebc6eb7..7302c8c 100644 --- a/src/log.rs +++ b/src/dev/log.rs @@ -114,7 +114,7 @@ pub fn timed(past: &Instant, message: &str) -> Instant { #[macro_export] macro_rules! tlog { ($instant:expr, $fmt:expr $(, $($arg:tt)+ )?) => {{ - $crate::log::timed($instant, &format!($fmt $(, $($arg)+ )?)) + $crate::dev::log::timed($instant, &format!($fmt $(, $($arg)+ )?)) }}; } @@ -129,26 +129,26 @@ pub fn elog(function: &str, message: &str) { macro_rules! log { ($level:path, $fmt:expr $(, $($arg:tt)+ )?) => {{ - let data = $crate::log::Data::new( + let data = $crate::dev::log::Data::new( Some($level), std::any::type_name_of_val(&|| {}), std::backtrace::Backtrace::capture(), ); if data.should_log { - $crate::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?)); + $crate::dev::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?)); } }}; ($fmt:expr $(, $($arg:tt)+ )?) => {{ - let data = $crate::log::Data::new( + let data = $crate::dev::log::Data::new( None, std::any::type_name_of_val(&|| {}), std::backtrace::Backtrace::capture(), ); if data.should_log { - $crate::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?)); + $crate::dev::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?)); }; }}; @@ -272,7 +272,7 @@ mod tests { fn test(&self); } - struct Logger {} + struct Logger; impl Loggable for Logger { fn test(&self) { diff --git a/src/log/level.rs b/src/dev/log/level.rs similarity index 100% rename from src/log/level.rs rename to src/dev/log/level.rs diff --git a/src/lib.rs b/src/lib.rs index 473bb4f..6d9c62a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,14 +2,13 @@ use std::{sync, time}; pub mod prelude { pub use crate::{ - log, - log::{Level::*, now}, - tlog, write_log, + dev::log::{Level::*, now}, + log, tlog, write_log, }; } +pub mod dev; pub mod graph; -pub mod log; pub mod router; pub mod syntax; diff --git a/src/main.rs b/src/main.rs index 23fe357..9382190 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::{backtrace, io, panic}; -use en::{ONSET, graph::Graph, log, prelude::*, syntax}; +use en::{ONSET, dev::log, graph::Graph, prelude::*, syntax}; #[tokio::main] #[expect(clippy::print_stderr, clippy::print_stdout, clippy::use_debug)] diff --git a/src/router/handlers/template.rs b/src/router/handlers/template.rs index 01bb7ea..8a375ee 100644 --- a/src/router/handlers/template.rs +++ b/src/router/handlers/template.rs @@ -6,6 +6,7 @@ use axum::{ }; use crate::{ + dev::log, prelude::*, router::{GlobalState, handlers::raw::make_response}, }; @@ -136,6 +137,13 @@ fn load_templates() -> Result { let root = PathBuf::from("templates"); let default_names: Vec<&str> = DEFAULTS.iter().map(|(n, _)| *n).collect(); + log!( + DEBUG, + "Reading templates from {}, canonical form {:?}", + root.display(), + root.canonicalize() + ); + match fs::read_dir(&root) { Ok(dir) => { for file_opt in dir { diff --git a/src/syntax/content/parser/lexeme.rs b/src/syntax/content/parser/lexeme.rs index 378a8b8..d0c1e3e 100644 --- a/src/syntax/content/parser/lexeme.rs +++ b/src/syntax/content/parser/lexeme.rs @@ -224,7 +224,7 @@ impl Lexeme { impl fmt::Display for Lexeme { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use crate::log::wrap; + use crate::dev::log::wrap; let properties = if self.last && self.first { "[S] " diff --git a/src/syntax/content/parser/token/anchor.rs b/src/syntax/content/parser/token/anchor.rs index 3702d77..12ee711 100644 --- a/src/syntax/content/parser/token/anchor.rs +++ b/src/syntax/content/parser/token/anchor.rs @@ -121,7 +121,7 @@ impl Parseable for Anchor { impl std::fmt::Display for Anchor { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - use crate::log::wrap; + use crate::dev::log::wrap; let wrapped_text = wrap(&self.text); let display_text = if wrapped_text.is_empty() { diff --git a/src/syntax/content/parser/token/literal.rs b/src/syntax/content/parser/token/literal.rs index 6991fb0..d812a64 100644 --- a/src/syntax/content/parser/token/literal.rs +++ b/src/syntax/content/parser/token/literal.rs @@ -23,7 +23,7 @@ impl Parseable for Literal { impl std::fmt::Display for Literal { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "Literal {}", crate::log::wrap(&self.text)) + write!(f, "Literal {}", crate::dev::log::wrap(&self.text)) } } From c30562782207068c502bf1677a2e5ea7e894a96e Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 16 Mar 2026 20:04:48 -0300 Subject: [PATCH 05/44] Add dev::test module for filesystem tests setup/teardown --- src/dev/test.rs | 135 ++++++++++++++++++++++++++++++++ src/graph.rs | 15 ++-- src/router/handlers/template.rs | 106 ++++++++++++++++++++----- 3 files changed, 227 insertions(+), 29 deletions(-) create mode 100644 src/dev/test.rs diff --git a/src/dev/test.rs b/src/dev/test.rs new file mode 100644 index 0000000..4813531 --- /dev/null +++ b/src/dev/test.rs @@ -0,0 +1,135 @@ +use std::{env, fs, io, path::PathBuf}; + +use crate::prelude::*; + +pub struct Directories { + pub original: PathBuf, + pub templates: PathBuf, + pub test: PathBuf, +} + +impl Directories { + /// Sets up self-cleaning original, temporary and 'templates' directories. + /// + /// # Errors + /// May return Error when: + /// - Current directory does not exist or lacking permissions + /// - Several I/O possibilities from directory creation failures + /// - Several I/O possibilities from working directory changing failures + pub fn setup(dir_name: &str) -> Result { + let original = env::current_dir()?; + let test = original.join(format!("target/mocks/{dir_name}")); + let templates = test.join("templates"); + + drop(fs::remove_dir_all(&test)); + + if let Err(error) = fs::create_dir_all(&test) { + return Err(Error::with_io( + "Failed test's directory creation", + error, + )) + } + + if let Err(error) = fs::create_dir_all(&templates) { + return Err(Error::with_io( + "Failed 'templates' directory creation", + error, + )) + } + + if let Err(error) = env::set_current_dir(&test) { + return Err(Error::with_io("Failed current directory change", error)) + } + + Ok(Directories { + original, + templates, + test, + }) + } +} + +impl Drop for Directories { + fn drop(&mut self) { + if let Err(error) = std::env::set_current_dir(&self.original) { + log!(ERROR, "Couldn't reset to original directory: {error}"); + } + if let Err(error) = std::fs::remove_dir_all(&self.test) { + log!(WARN, "Couldn't cleanup test directory: {error}"); + } + } +} + +#[derive(Debug)] +pub struct Error { + pub message: String, + pub inner_io: Option, + pub inner_tera: Option, +} + +impl Error { + fn with_io(message: &str, inner_io: io::Error) -> Error { + Error { + message: String::from(message), + inner_io: Some(inner_io), + inner_tera: None, + } + } +} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let mut message = self.message.clone(); + + if let Some(inner_io) = &self.inner_io { + message = format!("{message}\n{inner_io}"); + } + + if let Some(inner_tera) = &self.inner_tera { + message = format!("{message}\n{inner_tera}"); + } + + write!(f, "{message}") + } +} + +impl From for Error { + fn from(string: String) -> Error { + Error { + message: string, + inner_io: None, + inner_tera: None, + } + } +} + +impl From<&str> for Error { + fn from(str: &str) -> Error { Error::from(String::from(str)) } +} + +impl From for Error { + fn from(inner: io::Error) -> Error { + let mut error = Error::from(inner.to_string()); + error.inner_io = Some(inner); + error + } +} + +impl From for Error { + fn from(inner: tera::Error) -> Error { + let mut error = Error::from(inner.to_string()); + error.inner_tera = Some(inner); + error + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn bad_test_directory_name() { + let dirs = Directories::setup("\0"); + assert!(dirs.is_err()); + } +} diff --git a/src/graph.rs b/src/graph.rs index 7255479..7cdb7b6 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -1308,24 +1308,19 @@ mod tests { } #[cfg(test)] +#[expect(clippy::panic_in_result_fn)] mod serial_tests { use super::*; + use crate::dev::test::{Directories, Error}; #[test] - fn bad_graph_path() { - let original_working_directory = std::env::current_dir().unwrap(); - - assert!( - std::env::set_current_dir(std::path::Path::new( - "tests/mocks/no_graph" - )) - .is_ok() - ); + fn bad_graph_path() -> Result<(), Error> { + let _dirs = Directories::setup("bad_graph_path")?; let graph = Graph::load(); let message = graph.meta.messages.first().unwrap(); assert!(message.contains("Failed reading file at")); - assert!(std::env::set_current_dir(original_working_directory).is_ok()); + Ok(()) } } diff --git a/src/router/handlers/template.rs b/src/router/handlers/template.rs index 8a375ee..2fd7a83 100644 --- a/src/router/handlers/template.rs +++ b/src/router/handlers/template.rs @@ -496,33 +496,101 @@ mod tests { } #[cfg(test)] +#[expect(clippy::panic_in_result_fn)] mod serial_tests { + use std::{ffi::OsStr, os::unix::ffi::OsStrExt as _}; + use super::*; + use crate::dev::test::{Directories, Error}; - #[cfg_attr(not(unix), ignore)] #[test] - fn invalid_utf8_template_filename() { - use std::{ffi::OsStr, os::unix::ffi::OsStrExt as _, path::PathBuf}; + #[cfg_attr(not(unix), ignore)] + fn invalid_utf8_template_filename() -> Result<(), Error> { + let dirs = Directories::setup("encoding")?; - let original_working_directory = std::env::current_dir().unwrap(); - let base_dir = PathBuf::from("tests/mocks/encoding/temp"); - let templates_dir = base_dir.clone().join("templates"); - assert!(std::fs::create_dir_all(&base_dir).is_ok()); - assert!( - std::env::set_current_dir(&base_dir) - .is_ok() - ); - assert!(std::fs::create_dir_all(&templates_dir).is_ok()); + let invalid_name = OsStr::from_bytes(&[0xff, 0xfe, 0x80]); + let file_path = dirs.templates.join(invalid_name); + fs::write(file_path, b"")?; + let template_load_result = load_templates(); + let err = template_load_result.err().unwrap(); - let invalid_name = OsStr::from_bytes(&[0xff, 0xfe, 0x00]); - let file_path = templates_dir.join(invalid_name); - assert!(std::fs::write(&file_path, b"eNJq4FPUqSKoozdg").is_ok()); + let error_message = err.to_string(); + assert!(error_message.contains("not valid unicode")); - let result = load_templates(); - assert!(result.is_err()); + Ok(()) + } - assert!(std::fs::remove_dir_all(&base_dir).is_ok()); - assert!(std::env::set_current_dir(original_working_directory).is_ok()); + #[test] + fn custom_template() -> Result<(), Error> { + let dirs = Directories::setup("custom_template")?; + + let file_name = "custom.html"; + let file_path = dirs.templates.join(file_name); + fs::write(file_path, b"")?; + + let engine = load_templates()?; + assert!(engine.get_template_names().any(|t| t == "custom.html")); + + Ok(()) + } + + #[test] + fn custom_template_inheritance_error() -> Result<(), Error> { + let dirs = Directories::setup("custom_template")?; + + let file_name = "custom.html"; + let file_path = dirs.templates.join(file_name); + fs::write(file_path, br#"{% extends "nonexistent.html" %}"#)?; + + let template_load_result = load_templates(); + assert!(template_load_result.is_err()); + + Ok(()) + } + + #[test] + fn inner_template_no_op() -> Result<(), Error> { + let dirs = Directories::setup("inner_template")?; + + let inner_dir = dirs.templates.join("inner"); + fs::create_dir(&inner_dir)?; + let inner_template = inner_dir.join("inner.html"); + fs::write(inner_template, br#"{% extends "nonexistent.html" %}"#)?; + + let engine = load_templates()?; + let default_count = dirs.original.join("templates").read_dir()?.count(); + let template_count = engine.get_template_names().count(); + assert!(template_count == default_count); + + Ok(()) + } + + #[test] + fn templates_dir_not_found_ok() -> Result<(), Error> { + let dirs = Directories::setup("not_found_error")?; + + std::fs::remove_dir_all(&dirs.templates)?; + let template_load_result = load_templates(); + template_load_result?; + + Ok(()) + } + + #[test] + // Unexpected here means any error other than 'not found' + fn templates_dir_unexpected_error() -> Result<(), Error> { + let dirs = Directories::setup("unexpected_error")?; + + log!(DEBUG, "Working directory is {:?}", std::env::current_dir()); + + std::fs::remove_dir_all(&dirs.templates)?; + let templates = dirs.test.join("templates"); + fs::write(&templates, b"")?; + + let template_load_result = load_templates(); + assert!(template_load_result.is_err()); + + Ok(()) } } From 6af32696bed07bd12509faea315418d6b1115a67 Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 16 Mar 2026 20:07:27 -0300 Subject: [PATCH 06/44] Apply lints to all targets --- .clippy.toml | 1 + .justfile | 7 ++- Cargo.toml | 1 - src/graph.rs | 58 ++++++++++---------- src/graph/meta.rs | 1 - src/router/handlers/mime.rs | 45 ++++----------- src/syntax/content/parser/lexeme.rs | 6 +- src/syntax/content/parser/token/anchor.rs | 2 +- src/syntax/content/parser/token/bold.rs | 5 +- src/syntax/content/parser/token/checkbox.rs | 2 +- src/syntax/content/parser/token/code.rs | 5 +- src/syntax/content/parser/token/item.rs | 2 +- src/syntax/content/parser/token/linebreak.rs | 3 +- src/syntax/content/parser/token/literal.rs | 5 +- src/syntax/content/parser/token/oblique.rs | 2 +- src/syntax/content/parser/token/paragraph.rs | 2 +- src/syntax/content/parser/token/preformat.rs | 2 +- src/syntax/content/parser/token/strike.rs | 5 +- src/syntax/content/parser/token/underline.rs | 2 +- 19 files changed, 61 insertions(+), 95 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 4bda813..ee470c2 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -2,3 +2,4 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true single-char-binding-names-threshold = 2 upper-case-acronyms-aggressive = true +allow-indexing-slicing-in-tests = true diff --git a/.justfile b/.justfile index 4dc2004..6c04fc5 100644 --- a/.justfile +++ b/.justfile @@ -96,7 +96,7 @@ alias f := format # Lint [group: 'develop'] lint: - cargo +nightly clippy + cargo +nightly clippy --timings --all-targets alias l := lint @@ -228,9 +228,10 @@ alias fc := format-assess # Assess production lints [group: 'assess'] lint-assess: - cargo +nightly clippy -- \ - -D clippy::dbg_macro -D clippy::use_debug \ + cargo +nightly clippy --timings -- \ -D clippy::print_stdout -D clippy::print_stderr \ + -D clippy::dbg_macro -D clippy::use_debug + cargo +nightly clippy --timings --all-targets -- \ -D clippy::todo -D clippy::unimplemented -D clippy::unreachable alias la := lint-assess diff --git a/Cargo.toml b/Cargo.toml index de8f7a3..8b52c6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -211,7 +211,6 @@ shadow_reuse = "warn" shadow_same = "warn" shadow_unrelated = "warn" should_panic_without_expect = "warn" -similar_names = "warn" single_char_pattern = "warn" single_match_else = "warn" single_option_map = "warn" diff --git a/src/graph.rs b/src/graph.rs index 7cdb7b6..7e24eb0 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -721,8 +721,8 @@ mod tests { .unwrap(); graph.modulate(); - let node = graph.nodes.get("Node").unwrap(); - let connection = node.connections.get("Nowhere").unwrap(); + let node = &graph.nodes["Node"]; + let connection = &node.connections["Nowhere"]; assert!(connection.detached); } @@ -743,8 +743,8 @@ mod tests { .unwrap(); graph.modulate(); - let node = graph.nodes.get("NodeOne").unwrap(); - let connection = node.connections.get("NodeTwo").unwrap(); + let node = &graph.nodes["NodeOne"]; + let connection = &node.connections["NodeTwo"]; println!("{connection:#?}"); assert!(!connection.detached); } @@ -763,10 +763,10 @@ mod tests { .unwrap(); graph.modulate(); - let n01 = graph.nodes.get("n01").unwrap(); - let n02 = graph.nodes.get("n02").unwrap(); - let n01_to_n02 = n01.connections.get("n02").unwrap(); - let n02_to_n03 = n02.connections.get("n03").unwrap(); + let n01 = &graph.nodes["n01"]; + let n02 = &graph.nodes["n02"]; + let n01_to_n02 = &n01.connections["n02"]; + let n02_to_n03 = &n02.connections["n03"]; assert_eq!(n01_to_n02.from, "n01"); assert_eq!(n01_to_n02.to, "n02"); @@ -793,16 +793,16 @@ mod tests { .unwrap(); graph.modulate(); - let n01 = graph.nodes.get("n01").unwrap(); - let n02 = graph.nodes.get("n02").unwrap(); - let n04 = graph.nodes.get("n04").unwrap(); + let n01 = &graph.nodes["n01"]; + let n02 = &graph.nodes["n02"]; + let n04 = &graph.nodes["n04"]; - let n01_to_n02 = n01.connections.get("n02").unwrap(); - let n01_to_n03 = n01.connections.get("n03").unwrap(); - let n01_to_n04 = n01.connections.get("n04").unwrap(); + let n01_to_n02 = &n01.connections["n02"]; + let n01_to_n03 = &n01.connections["n03"]; + let n01_to_n04 = &n01.connections["n04"]; - let n04_to_n01 = n04.connections.get("n01").unwrap(); - let n04_to_n03 = n04.connections.get("n03").unwrap(); + let n04_to_n01 = &n04.connections["n01"]; + let n04_to_n03 = &n04.connections["n03"]; assert_eq!(n01_to_n02.from, "n01"); assert_eq!(n01_to_n02.to, "n02"); @@ -861,8 +861,8 @@ mod tests { .unwrap(); graph.modulate(); - assert!(graph.nodes.get("n01").unwrap().summary.contains(text)); - assert!(graph.nodes.get("n01").unwrap().text.contains(text)); + assert!(&graph.nodes["n01"].summary.contains(text)); + assert!(&graph.nodes["n01"].text.contains(text)); } #[test] @@ -881,8 +881,8 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, summary); - assert!(graph.nodes.get("n01").unwrap().text.contains(text)); + assert_eq!(&graph.nodes["n01"].summary, summary); + assert!(&graph.nodes["n01"].text.contains(text)); } #[test] @@ -900,7 +900,7 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, first_sentence); + assert_eq!(&graph.nodes["n01"].summary, first_sentence); } #[test] @@ -919,7 +919,7 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, first_paragraph); + assert_eq!(&graph.nodes["n01"].summary, first_paragraph); } #[test] @@ -948,7 +948,7 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, summary); + assert_eq!(graph.nodes["n01"].summary, summary); } #[test] @@ -967,9 +967,9 @@ mod tests { .unwrap(); graph.modulate(); - let n1_to_n2 = graph.nodes.get("n1").unwrap().connections.get("n2"); + let n1_to_n2 = &graph.nodes["n1"].connections.get("n2"); - let n2_to_n0 = graph.nodes.get("n2").unwrap().connections.get("n0"); + let n2_to_n0 = &graph.nodes["n2"].connections.get("n0"); println!("{n1_to_n2:#?}"); println!("{n2_to_n0:#?}"); @@ -991,8 +991,8 @@ mod tests { graph.modulate(); assert_eq!(graph.stats.detached_total, 2); - assert_eq!(*graph.stats.detached.get("anchor").unwrap(), 1); - assert_eq!(*graph.stats.detached.get("this one").unwrap(), 1); + assert_eq!(graph.stats.detached["anchor"], 1); + assert_eq!(graph.stats.detached["this one"], 1); } #[test] @@ -1008,7 +1008,7 @@ mod tests { graph.modulate(); assert_eq!(graph.stats.detached_total, 2); - assert_eq!(*graph.stats.detached.get("anchor").unwrap(), 2); + assert_eq!(graph.stats.detached["anchor"], 2); } #[test] @@ -1295,7 +1295,7 @@ mod tests { assert!(!format!("{none}").contains("exact")); let some = QueryResult { - node: Some(node.clone()), + node: Some(node), exact: false, redirect: false, }; diff --git a/src/graph/meta.rs b/src/graph/meta.rs index 5df4db0..4d4f56e 100644 --- a/src/graph/meta.rs +++ b/src/graph/meta.rs @@ -600,7 +600,6 @@ mod tests { assert!( validation_error .message - .clone() .unwrap() .contains("Splits to three elements: false") ); diff --git a/src/router/handlers/mime.rs b/src/router/handlers/mime.rs index 476ccc9..9d108e5 100644 --- a/src/router/handlers/mime.rs +++ b/src/router/handlers/mime.rs @@ -102,39 +102,18 @@ impl Mime { } } - pub fn kind(&self) -> Result { - let string = String::from(self.clone()); - let mut parts = string.split('/'); - let first_opt = parts.next(); - let second_opt = parts.next(); - if let Some(first) = first_opt - && let Some(second) = second_opt - { - if first == "application" { - if second == "toml" || second == "xml" || second == "json" { - Ok(Kind::Text) - } else if second == "pdf" - || second == "epub" - || second == "epub+zip" - || second == "octet-stream" - { - Ok(Kind::Blob) - } else { - Err(format!( - "Unexpected application kind for mimetype {string}" - )) - } - } else if first == "text" { - Ok(Kind::Text) - } else if first == "font" { - Ok(Kind::Font) - } else if first == "image" { - Ok(Kind::Image) - } else { - Err(format!("Could not determine a kind for mimetype {string}")) - } - } else { - Err(format!("Mimetype {string} couldn't be split on a slash")) + /// Returns one of four kind of mimetypes among text, font, image and blob. + /// + /// This is mainly used when serving assets through the `fixed` module in + /// order to determine what `Asset` field to use when assemblimg a response + /// body. + pub const fn kind(&self) -> Kind { + use Mime::*; + match self { + Txt | Csv | Css | Toml | Xml | Json | Js | Svg => Kind::Text, + Ttf | Otf | Woff | Woff2 => Kind::Font, + Ico | Jpeg | Png | Apng | Gif | Webp | Avif => Kind::Image, + Pdf | Epub | Unknown => Kind::Blob, } } } diff --git a/src/syntax/content/parser/lexeme.rs b/src/syntax/content/parser/lexeme.rs index d0c1e3e..495b27b 100644 --- a/src/syntax/content/parser/lexeme.rs +++ b/src/syntax/content/parser/lexeme.rs @@ -286,7 +286,7 @@ mod tests { fn first_segment() { let payload = "nhNc fGev QnGW E4hj ExyZ"; let lexeme = Lexeme::new(payload, "", ""); - assert_eq!(lexeme.clone().first_segment(), Some(String::from("nhNc"))); + assert_eq!(lexeme.first_segment(), Some(String::from("nhNc"))); } #[test] @@ -381,8 +381,8 @@ mod tests { let lexemes = Lexeme::collect(&input); let first = lexemes.first().unwrap(); - let second = lexemes.get(1).unwrap(); - let third = lexemes.get(2).unwrap(); + let second = &lexemes[1]; + let third = &lexemes[2]; let last = lexemes.last().unwrap(); assert_eq!( diff --git a/src/syntax/content/parser/token/anchor.rs b/src/syntax/content/parser/token/anchor.rs index 12ee711..54639df 100644 --- a/src/syntax/content/parser/token/anchor.rs +++ b/src/syntax/content/parser/token/anchor.rs @@ -216,7 +216,7 @@ mod tests { anchor.external = true; assert_eq!( - format!("{}", Token::Anchor(Box::new(anchor.clone()))), + format!("{}", Token::Anchor(Box::new(anchor))), "Tk:Anchor 'wPVo1 0OmYm' -> \"M1UEp 1gbfr\" \ +Leading +Balanced +External", ); diff --git a/src/syntax/content/parser/token/bold.rs b/src/syntax/content/parser/token/bold.rs index 6ef5bd3..6053ad7 100644 --- a/src/syntax/content/parser/token/bold.rs +++ b/src/syntax/content/parser/token/bold.rs @@ -60,10 +60,7 @@ mod tests { assert_eq!(format!("{}", Token::Bold(bold.clone())), "Tk:Bold [open]"); bold.open = false; - assert_eq!( - format!("{}", Token::Bold(bold.clone())), - "Tk:Bold [closed]" - ); + assert_eq!(format!("{}", Token::Bold(bold)), "Tk:Bold [closed]"); } #[test] diff --git a/src/syntax/content/parser/token/checkbox.rs b/src/syntax/content/parser/token/checkbox.rs index c2597b7..61bc61a 100644 --- a/src/syntax/content/parser/token/checkbox.rs +++ b/src/syntax/content/parser/token/checkbox.rs @@ -64,7 +64,7 @@ mod tests { checkbox.checked = false; assert_eq!( - format!("{}", Token::CheckBox(checkbox.clone())), + format!("{}", Token::CheckBox(checkbox)), "Tk:CheckBox [empty]" ); } diff --git a/src/syntax/content/parser/token/code.rs b/src/syntax/content/parser/token/code.rs index a6f6977..d11d5fe 100644 --- a/src/syntax/content/parser/token/code.rs +++ b/src/syntax/content/parser/token/code.rs @@ -60,9 +60,6 @@ mod tests { assert_eq!(format!("{}", Token::Code(code.clone())), "Tk:Code [open]"); code.open = false; - assert_eq!( - format!("{}", Token::Code(code.clone())), - "Tk:Code [closed]" - ); + assert_eq!(format!("{}", Token::Code(code)), "Tk:Code [closed]"); } } diff --git a/src/syntax/content/parser/token/item.rs b/src/syntax/content/parser/token/item.rs index a0b8321..02b34ee 100644 --- a/src/syntax/content/parser/token/item.rs +++ b/src/syntax/content/parser/token/item.rs @@ -80,7 +80,7 @@ mod tests { ); item.depth = None; assert_eq!( - format!("{}", Token::Item(item.clone())), + format!("{}", Token::Item(item)), "Tk:Item [] dRMy4" ); } diff --git a/src/syntax/content/parser/token/linebreak.rs b/src/syntax/content/parser/token/linebreak.rs index 023efd7..ea20a74 100644 --- a/src/syntax/content/parser/token/linebreak.rs +++ b/src/syntax/content/parser/token/linebreak.rs @@ -28,7 +28,6 @@ mod tests { #[test] fn token_display() { - let linebreak = LineBreak::default(); - assert_eq!(format!("{}", Token::LineBreak(linebreak)), "Tk:LineBreak"); + assert_eq!(format!("{}", Token::LineBreak(LineBreak)), "Tk:LineBreak"); } } diff --git a/src/syntax/content/parser/token/literal.rs b/src/syntax/content/parser/token/literal.rs index d812a64..e165d73 100644 --- a/src/syntax/content/parser/token/literal.rs +++ b/src/syntax/content/parser/token/literal.rs @@ -43,9 +43,6 @@ mod tests { ); literal.text = String::from("TjY02"); - assert_eq!( - format!("{}", Token::Literal(literal.clone())), - "Tk:Literal TjY02" - ); + assert_eq!(format!("{}", Token::Literal(literal)), "Tk:Literal TjY02"); } } diff --git a/src/syntax/content/parser/token/oblique.rs b/src/syntax/content/parser/token/oblique.rs index fa12ba2..7e4baf1 100644 --- a/src/syntax/content/parser/token/oblique.rs +++ b/src/syntax/content/parser/token/oblique.rs @@ -64,7 +64,7 @@ mod tests { oblique.open = false; assert_eq!( - format!("{}", Token::Oblique(oblique.clone())), + format!("{}", Token::Oblique(oblique)), "Tk:Oblique [closed]" ); } diff --git a/src/syntax/content/parser/token/paragraph.rs b/src/syntax/content/parser/token/paragraph.rs index ab635d2..3512320 100644 --- a/src/syntax/content/parser/token/paragraph.rs +++ b/src/syntax/content/parser/token/paragraph.rs @@ -89,7 +89,7 @@ mod tests { paragraph.open = None; assert_eq!( - format!("{}", Token::Paragraph(paragraph.clone())), + format!("{}", Token::Paragraph(paragraph)), "Tk:Paragraph [unknown]" ); } diff --git a/src/syntax/content/parser/token/preformat.rs b/src/syntax/content/parser/token/preformat.rs index 1ca0128..666ad68 100644 --- a/src/syntax/content/parser/token/preformat.rs +++ b/src/syntax/content/parser/token/preformat.rs @@ -85,7 +85,7 @@ mod tests { preformat.open = None; assert_eq!( - format!("{}", Token::PreFormat(preformat.clone())), + format!("{}", Token::PreFormat(preformat)), "Tk:PreFormat [unknown]" ); } diff --git a/src/syntax/content/parser/token/strike.rs b/src/syntax/content/parser/token/strike.rs index 4aadc56..2d98822 100644 --- a/src/syntax/content/parser/token/strike.rs +++ b/src/syntax/content/parser/token/strike.rs @@ -62,10 +62,7 @@ mod tests { ); strike.open = false; - assert_eq!( - format!("{}", Token::Strike(strike.clone())), - "Tk:Strike [closed]" - ); + assert_eq!(format!("{}", Token::Strike(strike)), "Tk:Strike [closed]"); } #[test] diff --git a/src/syntax/content/parser/token/underline.rs b/src/syntax/content/parser/token/underline.rs index bf60f1d..e8e2668 100644 --- a/src/syntax/content/parser/token/underline.rs +++ b/src/syntax/content/parser/token/underline.rs @@ -66,7 +66,7 @@ mod tests { underline.open = false; assert_eq!( - format!("{}", Token::Underline(underline.clone())), + format!("{}", Token::Underline(underline)), "Tk:Underline [closed]" ); } From d756a1613234b4459917f3e035a909cfeaba11ee Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 16 Mar 2026 20:08:08 -0300 Subject: [PATCH 07/44] Cleanup tests directory --- tests/containers/build.sh | 21 --------------------- tests/containers/run.sh | 12 ------------ tests/mocks/bad_graph/static/graph.toml | 3 --- tests/mocks/good_json/graph.json | 13 ------------- tests/mocks/no_graph/.git_placeholder | 0 5 files changed, 49 deletions(-) delete mode 100755 tests/containers/build.sh delete mode 100755 tests/containers/run.sh delete mode 100644 tests/mocks/bad_graph/static/graph.toml delete mode 100644 tests/mocks/good_json/graph.json delete mode 100644 tests/mocks/no_graph/.git_placeholder diff --git a/tests/containers/build.sh b/tests/containers/build.sh deleted file mode 100755 index f426ea2..0000000 --- a/tests/containers/build.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env sh - -set -eu -suffix=$(printf '%s' "$1" | sed 's/.*\.//') -tag="en:$suffix" - -if podman container exists "$tag"; then - podman stop --time 3 "$tag" -fi - -if [ "$suffix" = 'debian-dev' ]; then - cp ../../target/release/en en -elif [ "$suffix" = 'alpine-dev' ]; then - cp ../../target/x86_64-unknown-linux-musl/release/en en -fi - -podman build \ - --tag "$tag" \ - -f "Containerfile.$suffix" - -rm en diff --git a/tests/containers/run.sh b/tests/containers/run.sh deleted file mode 100755 index 784ec44..0000000 --- a/tests/containers/run.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env sh - -set -eu -suffix=$(printf '%s' "$1" | sed 's/.*\.//') -name="en-$suffix" -tag="en:$suffix" - -podman run \ - --replace \ - --name "$name" \ - --publish 3008:80 \ - "$tag" diff --git a/tests/mocks/bad_graph/static/graph.toml b/tests/mocks/bad_graph/static/graph.toml deleted file mode 100644 index 2d79863..0000000 --- a/tests/mocks/bad_graph/static/graph.toml +++ /dev/null @@ -1,3 +0,0 @@ -[meta] -config = { -' diff --git a/tests/mocks/good_json/graph.json b/tests/mocks/good_json/graph.json deleted file mode 100644 index 31363fb..0000000 --- a/tests/mocks/good_json/graph.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "nodes": { - "JSON": { - "text": "", - "title": "JSON", - "links": [], - "id": "JSON", - "hidden": false, - "connections": [] - } - }, - "root_node": "JSON" -} diff --git a/tests/mocks/no_graph/.git_placeholder b/tests/mocks/no_graph/.git_placeholder deleted file mode 100644 index e69de29..0000000 From 92287bc9c84425d45e0613c528c991f5572a774a Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 16 Mar 2026 20:10:11 -0300 Subject: [PATCH 08/44] justfile: Rename quick, add short recipes, tweak several - Add parameter for test filtering to test recipes - Add --timings option to supported cargo commands --- .justfile | 107 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 31 deletions(-) diff --git a/.justfile b/.justfile index 6c04fc5..3275053 100644 --- a/.justfile +++ b/.justfile @@ -50,30 +50,30 @@ run-watch-containerized: alias wc := run-watch-containerized [private] -quick-assess: - {{ just_cmd }} lint check quick-test-cover +assess-quick: + {{ just_cmd }} lint check test-cover-quick [private] -quick-assess-run: - -{{ just_cmd }} quick-assess +assess-run-quick: + -{{ just_cmd }} assess-quick {{ just_cmd }} run # Run quick assessments on changes [group: 'develop'] -quick-assess-watch: - {{ watch_cmd }} {{ just_cmd }} quick-assess +assess-watch-quick: + {{ watch_cmd }} {{ just_cmd }} assess-quick -alias qa := quick-assess-watch +alias qa := assess-watch-quick # Run quick assessments, build and serve on changes [group: 'develop'] -quick-assess-run-watch: - {{ watch_cmd }} {{ just_cmd }} quick-assess-run +assess-run-watch-quick: + {{ watch_cmd }} {{ just_cmd }} assess-run-quick -alias qr := quick-assess-run-watch +alias qr := assess-run-watch-quick [private] -quick-test-cover: +test-cover-quick: {{ cover_cmd }} --no-report -- --test 'serial_tests::' --test-threads 1 {{ cover_cmd }} --no-report -- --skip 'serial_tests::' {{ cover_cmd }} report --html @@ -81,10 +81,10 @@ quick-test-cover: # Quickly update coverage reports (inaccurate) [group: 'assess'] -quick-test-cover-watch: - {{ watch_cmd }} {{ just_cmd }} quick-test-cover +test-cover-watch-quick: + {{ watch_cmd }} {{ just_cmd }} test-cover-quick -alias qo := quick-test-cover-watch +alias qo := test-cover-watch-quick # Format all files [group: 'develop'] @@ -93,6 +93,26 @@ format: alias f := format +# Test (short output) +[group: 'develop'] +test-short pattern="": + cargo test {{ pattern }} -q --message-format short \ + -- 'serial_tests::' --test-threads=1 \ + --format=terse -- quiet + cargo test {{ pattern }} -q --message-format short --bin en + cargo test {{ pattern }} -q --message-format short --doc + cargo test {{ pattern }} --message-format short --lib \ + -- --format terse --skip 'serial_tests::' + +alias ts := test-short + +# Test on changes (shorter output) +[group: 'develop'] +test-short-watch: + {{ watch_cmd }} {{ just_cmd }} test-short + +alias tsw := test-short-watch + # Lint [group: 'develop'] lint: @@ -107,6 +127,20 @@ lint-watch: alias lw := lint-watch +# Lint (short output) +[group: 'develop'] +lint-short: + cargo +nightly clippy --all-targets -q --message-format short + +alias ls := lint-short + +# Lint on changes (shorter output) +[group: 'develop'] +lint-short-watch: + {{ watch_cmd }} {{ just_cmd }} lint-short + +alias lsw := lint-short-watch + # Run cargo check on changes [group: 'develop'] check-watch: @@ -136,8 +170,8 @@ alias x := fix # Run tests on changes [group: 'develop'] -test-watch: - {{ watch_cmd }} {{ just_cmd }} test +test-watch pattern="": + {{ watch_cmd }} {{ just_cmd }} test {{ pattern}} alias tw := test-watch @@ -198,14 +232,14 @@ alias pu := push-unsafe # Generate crate documentation [group: 'document'] doc: - cargo doc --document-private-items --no-deps + cargo doc --timings --document-private-items --no-deps alias d := doc # Generate crate and dependencies documentation [group: 'document'] doc-all: - cargo doc --document-private-items + cargo doc --timings --document-private-items alias da := doc-all @@ -223,7 +257,7 @@ alias do := doc-open format-assess: cargo +nightly fmt -- --check -alias fc := format-assess +alias fa := format-assess # Assess production lints [group: 'assess'] @@ -240,20 +274,28 @@ alias lp := lint-assess # Run cargo check [group: 'assess'] check: - {{ debug_vars }} cargo check --workspace + {{ debug_vars }} cargo check --workspace --all-targets \ + --future-incompat-report alias c := check # Run tests [group: 'assess'] -test: - cargo test -- --test 'serial_tests::' --test-threads 1 - cargo test --bin en - cargo test --doc - cargo test --lib -- --skip 'serial_tests::' +test pattern="": + cargo test {{ pattern}} --timings -- --test-threads=1 'serial_tests::' + cargo test {{ pattern}} --timings --bin en + cargo test {{ pattern}} --timings --doc + cargo test {{ pattern}} --timings --lib -- --skip 'serial_tests::' alias t := test +# Run tests with unfiltered output +[group: 'assess'] +test-output pattern="": + DEBUG=${DEBUG:-debug} cargo test {{ pattern }} -- --no-capture 2>&1 + +alias to := test-output + # Clean test coverage data [group: 'assess'] test-cover-clean: @@ -285,8 +327,11 @@ verify: git status exit 1 fi - {{ just_cmd }} todos-assess version-assess \ - security-assess format-assess lint-assess check test cover-assess + {{ just_cmd }} \ + todos-assess version-assess \ + security-assess \ + format-assess lint-assess check \ + test "" cover-assess alias v := verify @@ -330,7 +375,7 @@ alias cl := clean # Build [group: 'build'] build target=default_target: - cargo build --target {{ target }} --locked + cargo build --timings --target {{ target }} --locked alias b := build @@ -338,21 +383,21 @@ alias b := build # glibc build [group: 'build'] build-gnu: - cargo build --target {{ glibc_target }} --locked + cargo build --timings --target {{ glibc_target }} --locked alias bg := build-gnu # musl build [group: 'build'] build-musl: - cargo build --target {{ musl_target }} --locked + cargo build --timings --target {{ musl_target }} --locked alias bm := build-musl # Release build [group: 'build'] release-build target=default_target: - cargo build --target {{ target }} --locked --release + cargo build --timings --target {{ target }} --locked --release du -h target/{{ target }}/release/en alias rb := release-build From ce61c0df27b5610e5538f39d02388ff0891390c8 Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 16 Mar 2026 20:11:59 -0300 Subject: [PATCH 09/44] Improve asset mime handling robustness and readability --- Cargo.lock | 10 ++++---- Cargo.toml | 2 +- src/router/handlers/fixed.rs | 46 ++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c45ff9..a4170b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,9 +135,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "cc" -version = "1.2.56" +version = "1.2.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" dependencies = [ "find-msvc-tools", "shlex", @@ -259,7 +259,7 @@ dependencies = [ [[package]] name = "en" -version = "0.3.0-alpha" +version = "0.3.1-alpha" dependencies = [ "axum", "serde", @@ -616,9 +616,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.3" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "parse-zoneinfo" diff --git a/Cargo.toml b/Cargo.toml index 8b52c6b..b8a3e87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "en" -version = "0.3.0-alpha" +version = "0.3.1-alpha" description = "A non-linear writing instrument." license = "AGPL-3.0-only" diff --git a/src/router/handlers/fixed.rs b/src/router/handlers/fixed.rs index c274dc7..59c07a5 100644 --- a/src/router/handlers/fixed.rs +++ b/src/router/handlers/fixed.rs @@ -8,6 +8,7 @@ use axum::{ use serde::Serialize; use crate::{ + dev::log, graph::{Format, Graph, SerialErrorCause}, prelude::*, router::{ @@ -18,17 +19,6 @@ use crate::{ /// Assembles an HTTP response given Asset. fn assemble(asset: Asset, graph: &Graph) -> Response { - let kind = match asset.mime.kind() { - Ok(kind) => kind, - Err(error) => { - return error::make( - Some(500), - Some(&format!("Could not determine a mimetype kind: {error}")), - graph, - ) - }, - }; - let set_content_type = |response: &mut Response<_>, content_type: &str| { if let Ok(header_value) = HeaderValue::from_str(&String::from(content_type)) @@ -37,6 +27,8 @@ fn assemble(asset: Asset, graph: &Graph) -> Response { .headers_mut() .append(header::CONTENT_TYPE, header_value); } else { + // This should be unreachable considering the possible mimetypes + // and their string representations are internal to en log!( WARN, "Failed to create content type header value from {content_type}" @@ -44,7 +36,7 @@ fn assemble(asset: Asset, graph: &Graph) -> Response { } }; - match kind { + match asset.mime.kind() { mime::Kind::Text => { if let Some(text) = asset.text { let mut response = Response::new(Body::from(text)); @@ -54,6 +46,8 @@ fn assemble(asset: Asset, graph: &Graph) -> Response { ); response } else { + // This should be unreachable, considering the constructors + // will convert to text even if a blob is passed let mut response = error::make( Some(500), Some( @@ -75,6 +69,8 @@ fn assemble(asset: Asset, graph: &Graph) -> Response { ); response } else { + // This should be unreachable, considering the constructors + // will convert to blob even if a text is passed let mut response = error::make( Some(500), Some( @@ -182,7 +178,7 @@ struct Asset { impl Asset { fn new(blob: &[u8], mime: mime::Mime) -> Result { - match mime.kind()? { + match mime.kind() { mime::Kind::Text => Ok(Asset { text: Some(String::from_utf8(blob.to_vec())?), blob: None, @@ -198,19 +194,17 @@ impl Asset { } } - fn from_str(str: &str, mime: mime::Mime) -> Result { - match mime.kind()? { - mime::Kind::Text => Ok(Asset { + fn from_str(str: &str, mime: mime::Mime) -> Asset { + match mime.kind() { + mime::Kind::Text => Asset { text: Some(String::from(str)), blob: None, mime, - }), - mime::Kind::Font | mime::Kind::Image | mime::Kind::Blob => { - Ok(Asset { - text: None, - blob: Some(String::from(str).into_bytes()), - mime, - }) + }, + mime::Kind::Font | mime::Kind::Image | mime::Kind::Blob => Asset { + text: None, + blob: Some(String::from(str).into_bytes()), + mime, }, } } @@ -239,7 +233,7 @@ fn fallback(path: &str, graph: &Graph) -> Result { Err(io_error) => { if io_error.kind() == ErrorKind::NotFound { if let Some(content) = defaults.get(path) { - Asset::from_str(content, mime) + Ok(Asset::from_str(content, mime)) } else { let not_found_error = Err(AssetError::new( path, @@ -625,6 +619,8 @@ static CCND: License = License { #[cfg(test)] mod tests { + use axum::http::status::StatusCode; + use super::*; async fn wrap_serial(format: &str) -> Response { @@ -670,6 +666,6 @@ mod tests { graph: Graph::default(), }; let response = file(Path("/k/j/m".to_string()), State(state)).await; - assert!(response.status() == axum::http::status::StatusCode::NOT_FOUND); + assert!(response.status() == StatusCode::NOT_FOUND); } } From a60d6913c71a4307bfee07bf9cb3a8e6fbfa084f Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 16 Mar 2026 20:55:43 -0300 Subject: [PATCH 10/44] Fix order of 'quick' in some justfile recipes --- .justfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.justfile b/.justfile index 3275053..0112233 100644 --- a/.justfile +++ b/.justfile @@ -63,14 +63,14 @@ assess-run-quick: assess-watch-quick: {{ watch_cmd }} {{ just_cmd }} assess-quick -alias qa := assess-watch-quick +alias aq := assess-watch-quick # Run quick assessments, build and serve on changes [group: 'develop'] assess-run-watch-quick: {{ watch_cmd }} {{ just_cmd }} assess-run-quick -alias qr := assess-run-watch-quick +alias rq := assess-run-watch-quick [private] test-cover-quick: @@ -84,7 +84,7 @@ test-cover-quick: test-cover-watch-quick: {{ watch_cmd }} {{ just_cmd }} test-cover-quick -alias qo := test-cover-watch-quick +alias oq := test-cover-watch-quick # Format all files [group: 'develop'] From 9024e56e72b35bfbdcf8be17bda3a115645aec53 Mon Sep 17 00:00:00 2001 From: jutty Date: Tue, 17 Mar 2026 01:48:29 -0300 Subject: [PATCH 11/44] Update README with expanded long-term goals and a more detailed pitch --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 685af8e..4248c56 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,26 @@ # en -en is a tool to write non-linear, connected pieces of text and have their references mapped out as a graph of connected information. +en is a tool to write non-linear, connected pieces of text and have their references mapped out as a metadata-rich graph of connected information. -It works by ingesting a TOML file containing your node specification and serving it as a website that allows nodes to be browsed, searched and listed in relation to each other or as a shallow tree of nodes. - -## Roadmap - -For an outline of planned and completed features, see the [roadmap](https://en.jutty.dev/node/Roadmap). +It works by ingesting a graph definition that leverages TOML for metadata and a special markup language for prose. en can then serve this textual representation as a website (with other targets planned) that allows nodes to be explored. ## Learn more You can learn more and see what en looks like by visiting the [homepage](https://en.jutty.dev), which is rendered using en itself. +## Install and run + +See the [Documentation](https://en.jutty.dev/node/Documentation) page for instructions and how to install and start using en. + +## Roadmap + +On a high-level, here are some things that en intends to achieve at some point: + +1. Separate 'en' the server from 'en' the source-to-source translator. This would allow using en's markup syntax as a standalone compile-to-HTML language, effectively creating an "en cli" that should also have options to make it more practical to manipulate a graph, such as adding new nodes or querying your graph +3. Multifile graphs, with _optional_ TOML frontmatter +2. Make en more fitting to the 'note taking' use case +3. Multigraph, with the server being capable to let the user choose which graph to render and with inter-graph connections +4. Different rendering modes such as to a static website, to PDF or EPUB (with paper-friendly metadata) +5. Stateful and stateless online graph editing with 'export to TOML' + +For a more detailed outline of what's planned for the future of en, along with what's already been completed, see the [roadmap](https://en.jutty.dev/node/Roadmap). From dc4c331cb86f548ae63c4668a56f36bee6217c55 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 19 Mar 2026 23:37:39 -0300 Subject: [PATCH 12/44] Extend test coverage for test and fixed modules --- .justfile | 6 +- Cargo.lock | 32 ++++--- Cargo.toml | 1 - src/dev/test.rs | 59 +++++++++++- src/router/handlers/fixed.rs | 117 +++++++++++++++++++++-- src/syntax/content/parser/token/verse.rs | 61 ++++++++---- 6 files changed, 228 insertions(+), 48 deletions(-) diff --git a/.justfile b/.justfile index 0112233..14705dd 100644 --- a/.justfile +++ b/.justfile @@ -82,7 +82,8 @@ test-cover-quick: # Quickly update coverage reports (inaccurate) [group: 'assess'] test-cover-watch-quick: - {{ watch_cmd }} {{ just_cmd }} test-cover-quick + @{{ watch_cmd }} {{ just_cmd_no_ts }} test-cover-quick 2>&1 \ + | grep -v "process didn't exit successfully:" || true alias oq := test-cover-watch-quick @@ -441,9 +442,10 @@ glibc_target := "x86_64-unknown-linux-gnu" default_target := musl_target debug_vars := 'DEBUG=${DEBUG:-} DEBUG_FILTER=${DEBUG_FILTER:-} RUST_BACKTRACE=${RUST_BACKTRACE:-} RUSTFLAGS=${RUSTFLAGS:-}' +just_cmd := 'just --timestamp --explain --command-color green' +just_cmd_no_ts := 'just --explain --command-color green' watch_cmd := "watchexec -qc -r -e rs,toml,html --color always -- " cover_cmd := 'cargo llvm-cov --color always --ignore-filename-regex "main\.rs|log\.rs"' -just_cmd := 'just --timestamp --explain --command-color green' last_tag := `git tag --sort=-creatordate | head -1 | tr -d v` manifest_version := `grep "^version" Cargo.toml | cut -d \" -f 2` diff --git a/Cargo.lock b/Cargo.lock index a4170b3..87d028d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -528,9 +528,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "js-sys" @@ -1102,7 +1102,7 @@ dependencies = [ "toml_datetime", "toml_parser", "toml_writer", - "winnow", + "winnow 0.7.15", ] [[package]] @@ -1116,18 +1116,18 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.0.9+spec-1.1.0" +version = "1.0.10+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +checksum = "7df25b4befd31c4816df190124375d5a20c6b6921e2cad937316de3fccd63420" dependencies = [ - "winnow", + "winnow 1.0.0", ] [[package]] name = "toml_writer" -version = "1.0.6+spec-1.1.0" +version = "1.0.7+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" +checksum = "f17aaa1c6e3dc22b1da4b6bba97d066e354c7945cac2f7852d4e4e7ca7a6b56d" [[package]] name = "tower" @@ -1475,19 +1475,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" [[package]] -name = "zerocopy" -version = "0.8.42" +name = "winnow" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3" +checksum = "a90e88e4667264a994d34e6d1ab2d26d398dcdca8b7f52bec8668957517fc7d8" + +[[package]] +name = "zerocopy" +version = "0.8.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.42" +version = "0.8.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f" +checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index b8a3e87..d42bdc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -268,5 +268,4 @@ zero_sized_map_values = "warn" # cargo negative_feature_names = "warn" redundant_feature_names = "warn" -multiple_crate_versions = "warn" wildcard_dependencies = "warn" diff --git a/src/dev/test.rs b/src/dev/test.rs index 4813531..a644e30 100644 --- a/src/dev/test.rs +++ b/src/dev/test.rs @@ -2,9 +2,11 @@ use std::{env, fs, io, path::PathBuf}; use crate::prelude::*; +#[derive(Debug)] pub struct Directories { pub original: PathBuf, pub templates: PathBuf, + pub assets: PathBuf, pub test: PathBuf, } @@ -20,6 +22,7 @@ impl Directories { let original = env::current_dir()?; let test = original.join(format!("target/mocks/{dir_name}")); let templates = test.join("templates"); + let assets = test.join("static").join("public").join("assets"); drop(fs::remove_dir_all(&test)); @@ -37,6 +40,13 @@ impl Directories { )) } + if let Err(error) = fs::create_dir_all(&assets) { + return Err(Error::with_io( + "Failed 'assets' directory creation", + error, + )) + } + if let Err(error) = env::set_current_dir(&test) { return Err(Error::with_io("Failed current directory change", error)) } @@ -44,6 +54,7 @@ impl Directories { Ok(Directories { original, templates, + assets, test, }) } @@ -68,10 +79,10 @@ pub struct Error { } impl Error { - fn with_io(message: &str, inner_io: io::Error) -> Error { + fn with_io(message: &str, inner_error: io::Error) -> Error { Error { message: String::from(message), - inner_io: Some(inner_io), + inner_io: Some(inner_error), inner_tera: None, } } @@ -132,4 +143,48 @@ mod tests { let dirs = Directories::setup("\0"); assert!(dirs.is_err()); } + + #[test] + fn display_contains_str_from_from() { + let payload = "rHneusPkYNGW0Ia0"; + let error = Error::from(payload); + assert!(format!("{error}").contains(payload)); + } + + #[test] + fn display_contains_str_from_io_error() { + let payload = "SsVi0d3Ywc8kVhwp"; + let io_payload = "LoPbZP7cJEHzAjGW"; + let io_error = std::io::Error::other(io_payload); + let error = Error::with_io(payload, io_error); + assert!(format!("{error}").contains(payload)); + assert!(format!("{error}").contains(io_payload)); + } + + #[test] + fn from_io_error() { + let payload = "YgmTKBm3VtHt5h3x9"; + let io_error = std::io::Error::other(payload); + let error = Error::from(io_error); + + assert!(error.message.contains(payload)); + } +} + +#[cfg(test)] +mod serial_tests { + use super::*; + + #[test] + fn failed_working_directory_reset() { + let dirs = Directories::setup("\0"); + + let error = dirs.unwrap_err(); + println!("{error}"); + assert!(error.message.contains("Failed test's directory creation")); + assert!( + format!("{error}") + .contains("file name contained an unexpected NUL byte") + ); + } } diff --git a/src/router/handlers/fixed.rs b/src/router/handlers/fixed.rs index 59c07a5..770d139 100644 --- a/src/router/handlers/fixed.rs +++ b/src/router/handlers/fixed.rs @@ -86,9 +86,9 @@ fn assemble(asset: Asset, graph: &Graph) -> Response { } } -#[expect(clippy::upper_case_acronyms)] #[derive(Debug)] -enum AssetErrorKind { +#[expect(clippy::upper_case_acronyms)] +pub enum AssetErrorKind { NotFound, IO, UTF8, @@ -96,11 +96,11 @@ enum AssetErrorKind { } #[derive(Debug)] -struct AssetError { - path: String, - kind: AssetErrorKind, - io_error: Option, - utf8_error: Option, +pub struct AssetError { + pub path: String, + pub kind: AssetErrorKind, + pub io_error: Option, + pub utf8_error: Option, } impl AssetError { @@ -136,8 +136,7 @@ impl std::fmt::Display for AssetError { let mut message = match self.kind { AssetErrorKind::IO => { format!( - "A default fallback for {} was found, \ - but it could not be loaded", + "File {} was found, but it could not be loaded", self.path ) }, @@ -170,6 +169,7 @@ impl std::fmt::Display for AssetError { } } +#[derive(Debug)] struct Asset { blob: Option>, text: Option, @@ -224,13 +224,14 @@ fn fallback(path: &str, graph: &Graph) -> Result { let mime = mime::Mime::guess(path); match std::fs::read(&target) { - // A matching file exists on disk + // A matching file exists on disk and is accessible Ok(content) => Ok(Asset { blob: Some(content), text: None, mime, }), Err(io_error) => { + // A matching file does not exist on disk if io_error.kind() == ErrorKind::NotFound { if let Some(content) = defaults.get(path) { Ok(Asset::from_str(content, mime)) @@ -252,6 +253,7 @@ fn fallback(path: &str, graph: &Graph) -> Result { None => not_found_error, } } + // A matching file exists on disk and is not accessible } else { Err(AssetError::new( path, @@ -668,4 +670,99 @@ mod tests { let response = file(Path("/k/j/m".to_string()), State(state)).await; assert!(response.status() == StatusCode::NOT_FOUND); } + + #[test] + fn error_from_utf8error() { + let bytes = vec![0, 159]; + let utf8error = String::from_utf8(bytes.clone()).unwrap_err(); + let error = AssetError::from(utf8error); + assert!(error.utf8_error.is_some()); + assert_eq!(error.utf8_error.unwrap().into_bytes(), bytes); + } + + #[test] + fn error_from_string() { + let payload = "r5MDnkEojW9HZDAG"; + let asset_error = AssetError::from(payload.to_string()); + println!("{asset_error}"); + assert!(asset_error.path.contains(payload)); + } + + #[test] + fn new_text_asset() { + let asset = Asset::new(&[1, 0, 1], mime::Mime::Txt).unwrap(); + + assert!(asset.blob.is_none()); + assert!(asset.text.is_some()); + assert_eq!(asset.text.unwrap(), "\u{1}\0\u{1}"); + } + + #[test] + fn new_blob_asset() { + let asset = Asset::new(&[1, 0, 1], mime::Mime::Png).unwrap(); + + assert!(asset.blob.is_some()); + assert!(asset.text.is_none()); + assert_eq!(asset.blob.unwrap(), &[1, 0, 1]); + } + + #[test] + fn asset_from_str() { + let payload = "\u{1}\0\u{6}"; + let asset = Asset::from_str(payload, mime::Mime::Ico); + assert_eq!(asset.blob.unwrap(), &[1, 0, 6]); + } + + #[test] + fn new_asset_utf8_error() { + let bad_bytes = [0xff, 0xc0, 0xf5, 0xc1, 0x80]; + + let error = Asset::new(&bad_bytes, mime::Mime::Txt).unwrap_err(); + + assert!(matches!(&error.kind, AssetErrorKind::UTF8)); + assert!(format!("{error}").contains("UTF8 decoding error")); + } + + #[test] + fn not_found_fallback_error() { + let error = fallback("not_found.png", &Graph::default()).unwrap_err(); + + assert!(matches!(&error.kind, AssetErrorKind::NotFound)); + assert!( + format!("{error}") + .contains("The file was not found in the searched path") + ); + } +} + +#[cfg(test)] +#[expect(clippy::panic_in_result_fn)] +mod serial_tests { + use std::{fs, os::unix::fs::PermissionsExt as _}; + + use super::*; + use crate::dev::test::{Directories, Error}; + + #[test] + fn io_asset_error() -> Result<(), Error> { + let dirs = Directories::setup("io_asset_error")?; + + let assets = dirs.assets.clone(); + let file = assets.join("unreadable.png"); + + fs::write(&file, [1, 0, 1])?; + let mut permissions = fs::metadata(&file)?.permissions(); + permissions.set_mode(0o200); + fs::set_permissions(&file, permissions)?; + + let error = fallback("unreadable.png", &Graph::default()).unwrap_err(); + + assert!(matches!(&error.kind, AssetErrorKind::IO)); + assert!( + format!("{error}") + .contains("was found, but it could not be loaded") + ); + + Ok(()) + } } diff --git a/src/syntax/content/parser/token/verse.rs b/src/syntax/content/parser/token/verse.rs index 919929a..0c0d696 100644 --- a/src/syntax/content/parser/token/verse.rs +++ b/src/syntax/content/parser/token/verse.rs @@ -3,16 +3,10 @@ use crate::syntax::content::{Parseable, parser::Lexeme}; #[derive(Debug, Clone, Eq, PartialEq)] pub struct Verse { open: Option, - citation: Option, } impl Verse { - pub const fn new(open: bool) -> Verse { - Verse { - open: Some(open), - citation: None, - } - } + pub const fn new(open: bool) -> Verse { Verse { open: Some(open) } } pub fn probe_end(lexeme: &Lexeme) -> bool { lexeme.match_char_triple('\n', '&', '\n') @@ -24,12 +18,7 @@ impl Parseable for Verse { lexeme.match_char_triple('\n', '&', '\n') } - fn lex(_lexeme: &Lexeme) -> Verse { - Verse { - open: None, - citation: None, - } - } + fn lex(_lexeme: &Lexeme) -> Verse { Verse { open: None } } fn render(&self) -> String { if let Some(open) = self.open { @@ -59,12 +48,44 @@ impl std::fmt::Display for Verse { None => "unknown", }; - let citation = if self.citation.is_some() { - " cited" - } else { - "" - }; - - write!(f, "Verse [{display_open_state}{citation}]") + write!(f, "Verse [{display_open_state}]") + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn lexed_verse_is_empty() { + let verse = Verse::lex(&Lexeme::default()); + assert!(verse.open.is_none()); + } + + #[test] + fn flat_verse_is_empty() { + let verse = Verse::new(true); + assert!(verse.flatten().is_empty()); + } + + #[test] + #[should_panic( + expected = "Attempt to render a verse tag while open state is unknown" + )] + fn render_attempt_with_unknown_open_state() { + let verse = Verse::lex(&Lexeme::default()); + verse.render(); + } + + #[test] + fn display() { + let open = Verse::new(true); + assert_eq!(format!("{open}"), "Verse [open]"); + + let closed = Verse::new(false); + assert_eq!(format!("{closed}"), "Verse [closed]"); + + let unknown = Verse::lex(&Lexeme::default()); + assert_eq!(format!("{unknown}"), "Verse [unknown]"); } } From 58c1957e9fa5621d38666cf969156ba1f12e1060 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 19 Mar 2026 23:37:39 -0300 Subject: [PATCH 13/44] Extend test coverage for test and fixed modules --- .forgejo/workflows/verify.yaml | 16 +-- .justfile | 12 ++- Cargo.lock | 36 ++++--- Cargo.toml | 1 - src/dev/test.rs | 59 ++++++++++- src/router/handlers/fixed.rs | 121 +++++++++++++++++++++-- src/syntax/content/parser/token/verse.rs | 61 ++++++++---- 7 files changed, 249 insertions(+), 57 deletions(-) diff --git a/.forgejo/workflows/verify.yaml b/.forgejo/workflows/verify.yaml index a8ebe71..d4fb5f8 100644 --- a/.forgejo/workflows/verify.yaml +++ b/.forgejo/workflows/verify.yaml @@ -32,19 +32,21 @@ jobs: rustup target add x86_64-unknown-linux-musl - name: Setup additional tooling - run: .forgejo/workflows/setup-tools.sh + run: | + .forgejo/workflows/setup-tools.sh + git config --add safe.directory "$PWD" - name: Build - run: just build + run: just ci build - name: Format - run: just format-assess + run: just ci format-assess - name: Lint - run: just lint-assess + run: just ci lint-assess - name: Cargo check - run: just check + run: just ci check - name: Test - run: just test + run: just ci test - name: Assess test coverage - run: just cover-assess + run: just ci cover-assess diff --git a/.justfile b/.justfile index 0112233..6dc9ac6 100644 --- a/.justfile +++ b/.justfile @@ -82,7 +82,8 @@ test-cover-quick: # Quickly update coverage reports (inaccurate) [group: 'assess'] test-cover-watch-quick: - {{ watch_cmd }} {{ just_cmd }} test-cover-quick + @{{ watch_cmd }} {{ just_cmd_no_ts }} test-cover-quick 2>&1 \ + | grep -v "process didn't exit successfully:" || true alias oq := test-cover-watch-quick @@ -432,6 +433,12 @@ default: choose: @just --choose +[script, private] +ci recipe: + id -u ci >/dev/null 2>&1 || useradd -m ci + chown -R ci:ci . + su ci -c "just {{ recipe }}" + alias ch := choose export CARGO_TERM_COLOR := 'always' @@ -441,9 +448,10 @@ glibc_target := "x86_64-unknown-linux-gnu" default_target := musl_target debug_vars := 'DEBUG=${DEBUG:-} DEBUG_FILTER=${DEBUG_FILTER:-} RUST_BACKTRACE=${RUST_BACKTRACE:-} RUSTFLAGS=${RUSTFLAGS:-}' +just_cmd := 'just --timestamp --explain --command-color green' +just_cmd_no_ts := 'just --explain --command-color green' watch_cmd := "watchexec -qc -r -e rs,toml,html --color always -- " cover_cmd := 'cargo llvm-cov --color always --ignore-filename-regex "main\.rs|log\.rs"' -just_cmd := 'just --timestamp --explain --command-color green' last_tag := `git tag --sort=-creatordate | head -1 | tr -d v` manifest_version := `grep "^version" Cargo.toml | cut -d \" -f 2` diff --git a/Cargo.lock b/Cargo.lock index a4170b3..d5037d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -528,9 +528,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "js-sys" @@ -854,9 +854,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.9" +version = "0.103.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" dependencies = [ "ring", "rustls-pki-types", @@ -1102,7 +1102,7 @@ dependencies = [ "toml_datetime", "toml_parser", "toml_writer", - "winnow", + "winnow 0.7.15", ] [[package]] @@ -1116,18 +1116,18 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.0.9+spec-1.1.0" +version = "1.0.10+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +checksum = "7df25b4befd31c4816df190124375d5a20c6b6921e2cad937316de3fccd63420" dependencies = [ - "winnow", + "winnow 1.0.0", ] [[package]] name = "toml_writer" -version = "1.0.6+spec-1.1.0" +version = "1.0.7+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" +checksum = "f17aaa1c6e3dc22b1da4b6bba97d066e354c7945cac2f7852d4e4e7ca7a6b56d" [[package]] name = "tower" @@ -1475,19 +1475,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" [[package]] -name = "zerocopy" -version = "0.8.42" +name = "winnow" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3" +checksum = "a90e88e4667264a994d34e6d1ab2d26d398dcdca8b7f52bec8668957517fc7d8" + +[[package]] +name = "zerocopy" +version = "0.8.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.42" +version = "0.8.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f" +checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index b8a3e87..d42bdc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -268,5 +268,4 @@ zero_sized_map_values = "warn" # cargo negative_feature_names = "warn" redundant_feature_names = "warn" -multiple_crate_versions = "warn" wildcard_dependencies = "warn" diff --git a/src/dev/test.rs b/src/dev/test.rs index 4813531..a644e30 100644 --- a/src/dev/test.rs +++ b/src/dev/test.rs @@ -2,9 +2,11 @@ use std::{env, fs, io, path::PathBuf}; use crate::prelude::*; +#[derive(Debug)] pub struct Directories { pub original: PathBuf, pub templates: PathBuf, + pub assets: PathBuf, pub test: PathBuf, } @@ -20,6 +22,7 @@ impl Directories { let original = env::current_dir()?; let test = original.join(format!("target/mocks/{dir_name}")); let templates = test.join("templates"); + let assets = test.join("static").join("public").join("assets"); drop(fs::remove_dir_all(&test)); @@ -37,6 +40,13 @@ impl Directories { )) } + if let Err(error) = fs::create_dir_all(&assets) { + return Err(Error::with_io( + "Failed 'assets' directory creation", + error, + )) + } + if let Err(error) = env::set_current_dir(&test) { return Err(Error::with_io("Failed current directory change", error)) } @@ -44,6 +54,7 @@ impl Directories { Ok(Directories { original, templates, + assets, test, }) } @@ -68,10 +79,10 @@ pub struct Error { } impl Error { - fn with_io(message: &str, inner_io: io::Error) -> Error { + fn with_io(message: &str, inner_error: io::Error) -> Error { Error { message: String::from(message), - inner_io: Some(inner_io), + inner_io: Some(inner_error), inner_tera: None, } } @@ -132,4 +143,48 @@ mod tests { let dirs = Directories::setup("\0"); assert!(dirs.is_err()); } + + #[test] + fn display_contains_str_from_from() { + let payload = "rHneusPkYNGW0Ia0"; + let error = Error::from(payload); + assert!(format!("{error}").contains(payload)); + } + + #[test] + fn display_contains_str_from_io_error() { + let payload = "SsVi0d3Ywc8kVhwp"; + let io_payload = "LoPbZP7cJEHzAjGW"; + let io_error = std::io::Error::other(io_payload); + let error = Error::with_io(payload, io_error); + assert!(format!("{error}").contains(payload)); + assert!(format!("{error}").contains(io_payload)); + } + + #[test] + fn from_io_error() { + let payload = "YgmTKBm3VtHt5h3x9"; + let io_error = std::io::Error::other(payload); + let error = Error::from(io_error); + + assert!(error.message.contains(payload)); + } +} + +#[cfg(test)] +mod serial_tests { + use super::*; + + #[test] + fn failed_working_directory_reset() { + let dirs = Directories::setup("\0"); + + let error = dirs.unwrap_err(); + println!("{error}"); + assert!(error.message.contains("Failed test's directory creation")); + assert!( + format!("{error}") + .contains("file name contained an unexpected NUL byte") + ); + } } diff --git a/src/router/handlers/fixed.rs b/src/router/handlers/fixed.rs index 59c07a5..390e794 100644 --- a/src/router/handlers/fixed.rs +++ b/src/router/handlers/fixed.rs @@ -86,9 +86,9 @@ fn assemble(asset: Asset, graph: &Graph) -> Response { } } -#[expect(clippy::upper_case_acronyms)] #[derive(Debug)] -enum AssetErrorKind { +#[expect(clippy::upper_case_acronyms)] +pub enum AssetErrorKind { NotFound, IO, UTF8, @@ -96,11 +96,11 @@ enum AssetErrorKind { } #[derive(Debug)] -struct AssetError { - path: String, - kind: AssetErrorKind, - io_error: Option, - utf8_error: Option, +pub struct AssetError { + pub path: String, + pub kind: AssetErrorKind, + pub io_error: Option, + pub utf8_error: Option, } impl AssetError { @@ -136,8 +136,7 @@ impl std::fmt::Display for AssetError { let mut message = match self.kind { AssetErrorKind::IO => { format!( - "A default fallback for {} was found, \ - but it could not be loaded", + "File {} was found, but it could not be loaded", self.path ) }, @@ -170,6 +169,7 @@ impl std::fmt::Display for AssetError { } } +#[derive(Debug)] struct Asset { blob: Option>, text: Option, @@ -224,13 +224,14 @@ fn fallback(path: &str, graph: &Graph) -> Result { let mime = mime::Mime::guess(path); match std::fs::read(&target) { - // A matching file exists on disk + // A matching file exists on disk and is accessible Ok(content) => Ok(Asset { blob: Some(content), text: None, mime, }), Err(io_error) => { + // A matching file does not exist on disk if io_error.kind() == ErrorKind::NotFound { if let Some(content) = defaults.get(path) { Ok(Asset::from_str(content, mime)) @@ -252,6 +253,7 @@ fn fallback(path: &str, graph: &Graph) -> Result { None => not_found_error, } } + // A matching file exists on disk and is not accessible } else { Err(AssetError::new( path, @@ -668,4 +670,103 @@ mod tests { let response = file(Path("/k/j/m".to_string()), State(state)).await; assert!(response.status() == StatusCode::NOT_FOUND); } + + #[test] + fn error_from_utf8error() { + let bytes = vec![0, 159]; + let utf8error = String::from_utf8(bytes.clone()).unwrap_err(); + let error = AssetError::from(utf8error); + assert!(error.utf8_error.is_some()); + assert_eq!(error.utf8_error.unwrap().into_bytes(), bytes); + } + + #[test] + fn error_from_string() { + let payload = "r5MDnkEojW9HZDAG"; + let asset_error = AssetError::from(payload.to_string()); + println!("{asset_error}"); + assert!(asset_error.path.contains(payload)); + } + + #[test] + fn new_text_asset() { + let asset = Asset::new(&[1, 0, 1], mime::Mime::Txt).unwrap(); + + assert!(asset.blob.is_none()); + assert!(asset.text.is_some()); + assert_eq!(asset.text.unwrap(), "\u{1}\0\u{1}"); + } + + #[test] + fn new_blob_asset() { + let asset = Asset::new(&[1, 0, 1], mime::Mime::Png).unwrap(); + + assert!(asset.blob.is_some()); + assert!(asset.text.is_none()); + assert_eq!(asset.blob.unwrap(), &[1, 0, 1]); + } + + #[test] + fn asset_from_str() { + let payload = "\u{1}\0\u{6}"; + let asset = Asset::from_str(payload, mime::Mime::Ico); + assert_eq!(asset.blob.unwrap(), &[1, 0, 6]); + } + + #[test] + fn new_asset_utf8_error() { + let bad_bytes = [0xff, 0xc0, 0xf5, 0xc1, 0x80]; + + let error = Asset::new(&bad_bytes, mime::Mime::Txt).unwrap_err(); + + assert!(matches!(&error.kind, AssetErrorKind::UTF8)); + assert!(format!("{error}").contains("UTF8 decoding error")); + } + + #[test] + fn not_found_asset_error() { + let error = fallback("not_found.png", &Graph::default()).unwrap_err(); + + assert!(matches!(&error.kind, AssetErrorKind::NotFound)); + assert!( + format!("{error}") + .contains("The file was not found in the searched path") + ); + } +} + +#[cfg(test)] +#[cfg(unix)] +#[expect(clippy::panic_in_result_fn)] +mod serial_tests { + use std::{fs, os::unix::fs::PermissionsExt as _}; + + use super::*; + use crate::dev::test::{Directories, Error}; + + #[test] + fn io_asset_error() -> Result<(), Error> { + let dirs = Directories::setup("io_asset_error")?; + + let assets = dirs.assets.clone(); + let file = assets.join("unreadable.png"); + + fs::write(&file, [1, 0, 1])?; + let mut permissions = fs::metadata(&file)?.permissions(); + permissions.set_mode(0o200); + fs::set_permissions(&file, permissions)?; + + let new_permissions = fs::metadata(&file)?.permissions(); + assert_eq!(new_permissions.mode() & 0o777, 0o200); + + let error = fallback("unreadable.png", &Graph::default()).unwrap_err(); + + assert!(matches!(&error.kind, AssetErrorKind::IO)); + assert!( + format!("{error}") + .contains("was found, but it could not be loaded") + ); + + Ok(()) + } } diff --git a/src/syntax/content/parser/token/verse.rs b/src/syntax/content/parser/token/verse.rs index 919929a..0c0d696 100644 --- a/src/syntax/content/parser/token/verse.rs +++ b/src/syntax/content/parser/token/verse.rs @@ -3,16 +3,10 @@ use crate::syntax::content::{Parseable, parser::Lexeme}; #[derive(Debug, Clone, Eq, PartialEq)] pub struct Verse { open: Option, - citation: Option, } impl Verse { - pub const fn new(open: bool) -> Verse { - Verse { - open: Some(open), - citation: None, - } - } + pub const fn new(open: bool) -> Verse { Verse { open: Some(open) } } pub fn probe_end(lexeme: &Lexeme) -> bool { lexeme.match_char_triple('\n', '&', '\n') @@ -24,12 +18,7 @@ impl Parseable for Verse { lexeme.match_char_triple('\n', '&', '\n') } - fn lex(_lexeme: &Lexeme) -> Verse { - Verse { - open: None, - citation: None, - } - } + fn lex(_lexeme: &Lexeme) -> Verse { Verse { open: None } } fn render(&self) -> String { if let Some(open) = self.open { @@ -59,12 +48,44 @@ impl std::fmt::Display for Verse { None => "unknown", }; - let citation = if self.citation.is_some() { - " cited" - } else { - "" - }; - - write!(f, "Verse [{display_open_state}{citation}]") + write!(f, "Verse [{display_open_state}]") + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn lexed_verse_is_empty() { + let verse = Verse::lex(&Lexeme::default()); + assert!(verse.open.is_none()); + } + + #[test] + fn flat_verse_is_empty() { + let verse = Verse::new(true); + assert!(verse.flatten().is_empty()); + } + + #[test] + #[should_panic( + expected = "Attempt to render a verse tag while open state is unknown" + )] + fn render_attempt_with_unknown_open_state() { + let verse = Verse::lex(&Lexeme::default()); + verse.render(); + } + + #[test] + fn display() { + let open = Verse::new(true); + assert_eq!(format!("{open}"), "Verse [open]"); + + let closed = Verse::new(false); + assert_eq!(format!("{closed}"), "Verse [closed]"); + + let unknown = Verse::lex(&Lexeme::default()); + assert_eq!(format!("{unknown}"), "Verse [unknown]"); } } From 16088de2277211ec1eb2754ade3246a7fb370ef4 Mon Sep 17 00:00:00 2001 From: jutty Date: Sat, 21 Mar 2026 10:28:49 -0300 Subject: [PATCH 14/44] Move ci user setup to workflow file --- .forgejo/workflows/verify.yaml | 7 +++++-- .justfile | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.forgejo/workflows/verify.yaml b/.forgejo/workflows/verify.yaml index d4fb5f8..4440769 100644 --- a/.forgejo/workflows/verify.yaml +++ b/.forgejo/workflows/verify.yaml @@ -32,9 +32,12 @@ jobs: rustup target add x86_64-unknown-linux-musl - name: Setup additional tooling + run: .forgejo/workflows/setup-tools.sh + + - name: Setup permissions for ci user run: | - .forgejo/workflows/setup-tools.sh - git config --add safe.directory "$PWD" + useradd -m ci && chown -R ci:ci . + git config --global --add safe.directory "$PWD" - name: Build run: just ci build diff --git a/.justfile b/.justfile index 6dc9ac6..0236f9f 100644 --- a/.justfile +++ b/.justfile @@ -433,13 +433,13 @@ default: choose: @just --choose +alias ch := choose + [script, private] ci recipe: - id -u ci >/dev/null 2>&1 || useradd -m ci - chown -R ci:ci . su ci -c "just {{ recipe }}" -alias ch := choose +## VARIABLES export CARGO_TERM_COLOR := 'always' @@ -460,4 +460,6 @@ lockfile_version := ``` | grep version | cut -d '"' -f 2 ``` +## OPTIONS + set unstable From 3f69fe87f6c2a6f99aed9c959ea388a1b179bb79 Mon Sep 17 00:00:00 2001 From: jutty Date: Sat, 21 Mar 2026 10:30:36 -0300 Subject: [PATCH 15/44] Bump just version and set lazy option --- .forgejo/workflows/setup-tools.sh | 4 ++-- .justfile | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/setup-tools.sh b/.forgejo/workflows/setup-tools.sh index cd38738..ff6e814 100755 --- a/.forgejo/workflows/setup-tools.sh +++ b/.forgejo/workflows/setup-tools.sh @@ -2,8 +2,8 @@ set -eu -JUST_VERSION="1.45.0" -JUST_SHA256SUM="dc3f958aaf8c6506dd90426e9b03f86dd15e74a6467ee0e54929f750af3d9e49" +JUST_VERSION="1.47.1" +JUST_SHA256SUM="3cb931ae25860f261ee373f32ede3b772ac91f14f588e4071576d3ffcf1a16fd" CARGO_LLVM_COV_VERSION="0.6.21" CARGO_LLVM_COV_SHA256SUM="57f491aedf7cdb261538ceb49cbb1ee9d27df7ca205a5e1a009caaf5cb911afb" CARGO_AUDIT_VERSION="0.22.1" diff --git a/.justfile b/.justfile index 0236f9f..7c9d28a 100644 --- a/.justfile +++ b/.justfile @@ -463,3 +463,4 @@ lockfile_version := ``` ## OPTIONS set unstable +set lazy From 024b0a06ee96890f9a9ae2dc410d8259a0509d83 Mon Sep 17 00:00:00 2001 From: jutty Date: Sat, 21 Mar 2026 10:53:14 -0300 Subject: [PATCH 16/44] Rename CI user setup step --- .forgejo/workflows/verify.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/verify.yaml b/.forgejo/workflows/verify.yaml index 4440769..2d4e590 100644 --- a/.forgejo/workflows/verify.yaml +++ b/.forgejo/workflows/verify.yaml @@ -34,7 +34,7 @@ jobs: - name: Setup additional tooling run: .forgejo/workflows/setup-tools.sh - - name: Setup permissions for ci user + - name: Setup CI user run: | useradd -m ci && chown -R ci:ci . git config --global --add safe.directory "$PWD" From 6180bb371f88925c0a038813f78e73b9629cd32f Mon Sep 17 00:00:00 2001 From: jutty Date: Sat, 21 Mar 2026 15:44:17 -0300 Subject: [PATCH 17/44] Add several tests to dev/test, router handlers and syntax tokens --- src/dev/test.rs | 21 ++++ src/router/handlers/fixed.rs | 113 ++++++++++++++++++- src/syntax/content/parser/context.rs | 23 ++++ src/syntax/content/parser/token/anchor.rs | 11 ++ src/syntax/content/parser/token/bold.rs | 3 + src/syntax/content/parser/token/checkbox.rs | 3 + src/syntax/content/parser/token/code.rs | 9 ++ src/syntax/content/parser/token/header.rs | 9 ++ src/syntax/content/parser/token/item.rs | 13 ++- src/syntax/content/parser/token/linebreak.rs | 6 + src/syntax/content/parser/token/list.rs | 9 ++ src/syntax/content/parser/token/literal.rs | 8 ++ src/syntax/content/parser/token/oblique.rs | 3 + src/syntax/content/parser/token/paragraph.rs | 11 ++ src/syntax/content/parser/token/preformat.rs | 3 + src/syntax/content/parser/token/quote.rs | 105 ++++++++++++++++- src/syntax/content/parser/token/strike.rs | 3 + src/syntax/content/parser/token/table.rs | 98 +++++++++++++++- src/syntax/content/parser/token/underline.rs | 3 + src/syntax/content/parser/token/verse.rs | 12 +- 20 files changed, 456 insertions(+), 10 deletions(-) diff --git a/src/dev/test.rs b/src/dev/test.rs index a644e30..8a4ec15 100644 --- a/src/dev/test.rs +++ b/src/dev/test.rs @@ -161,6 +161,18 @@ mod tests { assert!(format!("{error}").contains(io_payload)); } + #[test] + fn display_contains_str_from_tera_error() { + let payload = "pA6B0LhiiDMNCl1J"; + let tera_payload = "5ob8H594dCAQ8pfk"; + let error = Error { + message: payload.to_string(), + inner_tera: Some(tera::Error::msg(tera_payload)), + inner_io: None, + }; + assert!(format!("{error}").contains(payload)); + assert!(format!("{error}").contains(tera_payload)); + } #[test] fn from_io_error() { let payload = "YgmTKBm3VtHt5h3x9"; @@ -169,6 +181,15 @@ mod tests { assert!(error.message.contains(payload)); } + + #[test] + fn from_tera_error() { + let payload = "XEB3dcvYuz0M1lYt"; + let tera_error = tera::Error::msg(payload); + let error = Error::from(tera_error); + + assert!(error.message.contains(payload)); + } } #[cfg(test)] diff --git a/src/router/handlers/fixed.rs b/src/router/handlers/fixed.rs index 390e794..d9bd120 100644 --- a/src/router/handlers/fixed.rs +++ b/src/router/handlers/fixed.rs @@ -624,6 +624,7 @@ mod tests { use axum::http::status::StatusCode; use super::*; + use crate::router::handlers::mime::Mime; async fn wrap_serial(format: &str) -> Response { let state = GlobalState { @@ -733,16 +734,28 @@ mod tests { .contains("The file was not found in the searched path") ); } + + #[test] + fn assemble_from_blob() { + let asset = Asset::new(&[1, 0, 1], Mime::Pdf).unwrap(); + let response = assemble(asset, &Graph::default()); + let content_type = + response.headers().get(header::CONTENT_TYPE).unwrap(); + assert_eq!(content_type, "application/pdf"); + } } #[cfg(test)] #[cfg(unix)] -#[expect(clippy::panic_in_result_fn)] +#[expect(clippy::panic_in_result_fn, clippy::unwrap_in_result)] mod serial_tests { - use std::{fs, os::unix::fs::PermissionsExt as _}; + use std::{fs, os::unix::fs::PermissionsExt as _, path::PathBuf}; use super::*; - use crate::dev::test::{Directories, Error}; + use crate::{ + dev::test::{Directories, Error}, + router::handlers::mime::Mime, + }; #[test] fn io_asset_error() -> Result<(), Error> { @@ -769,4 +782,98 @@ mod serial_tests { Ok(()) } + + #[test] + fn target_file_exists() -> Result<(), Error> { + let dirs = Directories::setup("target_file_exists")?; + + let assets = dirs.assets.clone(); + let file = assets.join("asset.woff2"); + + fs::write(&file, [1, 0, 1])?; + let asset = fallback("asset.woff2", &Graph::default()).unwrap(); + assert!(asset.text.is_none()); + assert!(asset.blob.is_some()); + assert!(matches!(asset.mime, Mime::Woff2)); + + Ok(()) + } + + #[test] + fn default_font_found_if_serving_enabled() -> Result<(), Error> { + let dirs = Directories::setup("font_found_if_serving_enabled")?; + + let assets = dirs.assets.clone(); + let relative_font_path = + PathBuf::from(FONTS[0].0.replace("assets/", "")); + let font_path = assets.join(&relative_font_path); + let font_dir = font_path.parent().expect("failed getting font dir"); + + println!("{font_dir:?}"); + fs::create_dir_all(font_dir)?; + fs::write(&font_path, [1, 0, 1])?; + let graph = Graph::from_serial( + "[meta.config]\nserve_fonts = true", + &Format::TOML, + ) + .expect("failed instantiating graph"); + println!("{font_path:?}"); + let asset = fallback(relative_font_path.to_str().unwrap(), &graph) + .expect("fallback failed"); + + assert!(asset.text.is_none()); + assert!(asset.blob.is_some()); + assert!(matches!(asset.mime, Mime::Woff2)); + + Ok(()) + } + + #[test] + fn custom_font_found_if_serving_enabled() -> Result<(), Error> { + let dirs = Directories::setup("font_found_if_serving_enabled")?; + + let assets = dirs.assets.clone(); + let relative_font_path = "fonts/custom.ttf"; + let font_path = assets.join(relative_font_path); + let font_dir = font_path.parent().unwrap(); + + fs::create_dir_all(font_dir)?; + fs::write(&font_path, [1, 0, 1])?; + let graph = Graph::from_serial( + "[meta.config]\nserve_fonts = true", + &Format::TOML, + ) + .expect("failed instantiating graph"); + let asset = + fallback(relative_font_path, &graph).expect("fallback failed"); + + assert!(asset.text.is_none()); + assert!(asset.blob.is_some()); + assert!(matches!(asset.mime, Mime::Ttf)); + + Ok(()) + } + + #[test] + fn font_not_found_if_serving_disabled() -> Result<(), Error> { + let dirs = Directories::setup("target_file_exists")?; + + let assets = dirs.assets.clone(); + let relative_font_path = + PathBuf::from(FONTS[0].0.replace("assets/", "")); + let font_path = assets.join(&relative_font_path); + let font_dir = font_path.parent().unwrap(); + + fs::create_dir_all(font_dir)?; + fs::write(&font_path, [1, 0, 1])?; + let graph = Graph::from_serial( + "[meta.config]\nserve_fonts = false", + &Format::TOML, + ) + .unwrap(); + let error = fallback(font_path.to_str().unwrap(), &graph).unwrap_err(); + assert!(matches!(error.kind, AssetErrorKind::NotFound)); + + Ok(()) + } } diff --git a/src/syntax/content/parser/context.rs b/src/syntax/content/parser/context.rs index 6320a5d..e5010f6 100644 --- a/src/syntax/content/parser/context.rs +++ b/src/syntax/content/parser/context.rs @@ -77,4 +77,27 @@ mod tests { state.context.block = Block::List; super::close(&state, &mut vec![]); } + + #[test] + #[should_panic(expected = "End of input with open quote")] + fn open_quote_eoi() { + let mut state = State::default(); + state.context.block = Block::Quote; + super::close(&state, &mut vec![]); + } + + #[test] + #[should_panic(expected = "End of input with open table")] + fn open_table_eoi() { + let mut state = State::default(); + state.context.block = Block::Table; + super::close(&state, &mut vec![]); + } + + #[test] + fn open_verse_eoi() { + let mut state = State::default(); + state.context.block = Block::Verse; + super::close(&state, &mut vec![]); + } } diff --git a/src/syntax/content/parser/token/anchor.rs b/src/syntax/content/parser/token/anchor.rs index 54639df..1efecf9 100644 --- a/src/syntax/content/parser/token/anchor.rs +++ b/src/syntax/content/parser/token/anchor.rs @@ -261,4 +261,15 @@ mod tests { let anchor = Anchor::default(); assert_eq!(format!("{anchor}"), "Anchor -> "); } + + #[test] + fn flatten() { + let payload = "tpBTViYnldoTqDsB"; + let mut anchor = Anchor::default(); + anchor.text = String::from(payload); + assert_eq!(anchor.flatten(), payload); + + let token = Token::Anchor(Box::new(anchor)); + assert_eq!(token.flatten(), payload); + } } diff --git a/src/syntax/content/parser/token/bold.rs b/src/syntax/content/parser/token/bold.rs index 6053ad7..6ae041e 100644 --- a/src/syntax/content/parser/token/bold.rs +++ b/src/syntax/content/parser/token/bold.rs @@ -67,5 +67,8 @@ mod tests { fn flatten() { let bold = Bold::new(false); assert_eq!(bold.flatten(), ""); + + let token = Token::Bold(bold); + assert_eq!(token.flatten(), ""); } } diff --git a/src/syntax/content/parser/token/checkbox.rs b/src/syntax/content/parser/token/checkbox.rs index 61bc61a..9230af6 100644 --- a/src/syntax/content/parser/token/checkbox.rs +++ b/src/syntax/content/parser/token/checkbox.rs @@ -73,5 +73,8 @@ mod tests { fn flatten() { let checkbox = CheckBox::new(false); assert_eq!(checkbox.flatten(), ""); + + let token = Token::CheckBox(checkbox); + assert_eq!(token.flatten(), ""); } } diff --git a/src/syntax/content/parser/token/code.rs b/src/syntax/content/parser/token/code.rs index d11d5fe..8f82eba 100644 --- a/src/syntax/content/parser/token/code.rs +++ b/src/syntax/content/parser/token/code.rs @@ -62,4 +62,13 @@ mod tests { code.open = false; assert_eq!(format!("{}", Token::Code(code)), "Tk:Code [closed]"); } + + #[test] + fn flatten() { + let code = Code::new(true); + assert_eq!(code.flatten(), ""); + + let token = Token::Code(code); + assert_eq!(token.flatten(), ""); + } } diff --git a/src/syntax/content/parser/token/header.rs b/src/syntax/content/parser/token/header.rs index 1f5fe02..9de3b5d 100644 --- a/src/syntax/content/parser/token/header.rs +++ b/src/syntax/content/parser/token/header.rs @@ -322,4 +322,13 @@ mod tests { format!("Header [unknown L1 DOM ID {payload}]") ); } + + #[test] + fn flatten() { + let header = Header::new(Level::Two, true, Some("MNxqaFfIbCzw")); + assert_eq!(header.flatten(), ""); + + let token = Token::Header(header); + assert_eq!(token.flatten(), ""); + } } diff --git a/src/syntax/content/parser/token/item.rs b/src/syntax/content/parser/token/item.rs index 02b34ee..0e36144 100644 --- a/src/syntax/content/parser/token/item.rs +++ b/src/syntax/content/parser/token/item.rs @@ -53,11 +53,21 @@ mod tests { #[should_panic( expected = "Items should only be rendered by a list's render method" )] - fn render() { + fn token_render() { let item = Item::new("aCNuZwwzrt", None); item.render(); } + #[test] + #[should_panic( + expected = "Items should only be rendered by a list's render method" + )] + fn render() { + let item = Item::new("vuv3ipykTzuf", None); + let token = Token::Item(item); + token.render(); + } + #[test] fn probe() { let lexeme = Lexeme::new("bOa", "2R6", "4Mp"); @@ -89,5 +99,6 @@ mod tests { fn flatten() { let item = Item::new("", None); assert_eq!(item.flatten(), ""); + assert_eq!(Token::Item(item).flatten(), ""); } } diff --git a/src/syntax/content/parser/token/linebreak.rs b/src/syntax/content/parser/token/linebreak.rs index ea20a74..65ccc73 100644 --- a/src/syntax/content/parser/token/linebreak.rs +++ b/src/syntax/content/parser/token/linebreak.rs @@ -30,4 +30,10 @@ mod tests { fn token_display() { assert_eq!(format!("{}", Token::LineBreak(LineBreak)), "Tk:LineBreak"); } + + #[test] + fn flatten() { + assert_eq!(LineBreak.flatten(), "\n"); + assert_eq!(Token::LineBreak(LineBreak).flatten(), "\n"); + } } diff --git a/src/syntax/content/parser/token/list.rs b/src/syntax/content/parser/token/list.rs index db7aff1..1120b9d 100644 --- a/src/syntax/content/parser/token/list.rs +++ b/src/syntax/content/parser/token/list.rs @@ -232,4 +232,13 @@ mod tests { \n\n" ); } + + #[test] + fn flatten() { + let list = List::new(true); + assert_eq!(list.flatten(), "[List: 0 items]"); + + let token = Token::List(List::new(true)); + assert_eq!(token.flatten(), "[List: 0 items]"); + } } diff --git a/src/syntax/content/parser/token/literal.rs b/src/syntax/content/parser/token/literal.rs index e165d73..236ee41 100644 --- a/src/syntax/content/parser/token/literal.rs +++ b/src/syntax/content/parser/token/literal.rs @@ -45,4 +45,12 @@ mod tests { literal.text = String::from("TjY02"); assert_eq!(format!("{}", Token::Literal(literal)), "Tk:Literal TjY02"); } + + #[test] + fn flatten() { + let payload = "vJtsvWD7ErYB"; + let literal = Literal::lex(&Lexeme::new(payload, "", "")); + assert_eq!(literal.flatten(), payload); + assert_eq!(Token::Literal(literal).flatten(), payload); + } } diff --git a/src/syntax/content/parser/token/oblique.rs b/src/syntax/content/parser/token/oblique.rs index 7e4baf1..a156a19 100644 --- a/src/syntax/content/parser/token/oblique.rs +++ b/src/syntax/content/parser/token/oblique.rs @@ -73,5 +73,8 @@ mod tests { fn flatten() { let oblique = Oblique::new(false); assert_eq!(oblique.flatten(), ""); + + let token = Token::Oblique(oblique); + assert_eq!(token.flatten(), ""); } } diff --git a/src/syntax/content/parser/token/paragraph.rs b/src/syntax/content/parser/token/paragraph.rs index 3512320..c0756af 100644 --- a/src/syntax/content/parser/token/paragraph.rs +++ b/src/syntax/content/parser/token/paragraph.rs @@ -93,4 +93,15 @@ mod tests { "Tk:Paragraph [unknown]" ); } + + #[test] + fn flatten() { + let open = Paragraph::new(true); + let closed = Paragraph::new(false); + + assert_eq!(open.flatten(), ""); + assert_eq!(closed.flatten(), ""); + assert_eq!(Token::Paragraph(open).flatten(), ""); + assert_eq!(Token::Paragraph(closed).flatten(), ""); + } } diff --git a/src/syntax/content/parser/token/preformat.rs b/src/syntax/content/parser/token/preformat.rs index 666ad68..d950590 100644 --- a/src/syntax/content/parser/token/preformat.rs +++ b/src/syntax/content/parser/token/preformat.rs @@ -94,5 +94,8 @@ mod tests { fn flatten() { let preformat = PreFormat::new(false); assert_eq!(preformat.flatten(), ""); + + let token = Token::PreFormat(preformat); + assert_eq!(token.flatten(), ""); } } diff --git a/src/syntax/content/parser/token/quote.rs b/src/syntax/content/parser/token/quote.rs index a6d144d..397b41f 100644 --- a/src/syntax/content/parser/token/quote.rs +++ b/src/syntax/content/parser/token/quote.rs @@ -26,7 +26,9 @@ impl Parseable for Quote { lexeme.match_char('>') && lexeme.match_next_char(' ') } - fn lex(_lexeme: &Lexeme) -> Quote { Quote::default() } + fn lex(_lexeme: &Lexeme) -> Quote { + panic!("Attempt to lex a quote directly from a lexeme") + } fn render(&self) -> String { let opening = if let Some(url) = &self.url { @@ -47,7 +49,13 @@ impl Parseable for Quote { format!("\n{opening}\n{content}\n\n") } - fn flatten(&self) -> String { String::default() } + fn flatten(&self) -> String { + if let Some(citation) = &self.citation { + format!(r#""{}" -- {}"#, self.text, citation) + } else { + format!(r#""{}""#, self.text) + } + } } impl std::fmt::Display for Quote { @@ -63,3 +71,96 @@ impl std::fmt::Display for Quote { write!(f, "Quote [{}]", meta.trim()) } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::syntax::content::parser::Token; + + #[test] + fn display() { + let mut quote_slim = Quote::default(); + quote_slim.text = "iXh0141J7B8P46Gv".to_string(); + + println!("{quote_slim}"); + assert!(format!("{quote_slim}").contains("Quote")); + assert!(!format!("{quote_slim}").contains("+url")); + assert!(!format!("{quote_slim}").contains("+citation")); + assert_eq!(format!("{}", Token::Quote(quote_slim)), "Tk:Quote []"); + + let mut quote_cited = Quote::default(); + quote_cited.text = "iXh0141J7B8P46Gv".to_string(); + quote_cited.citation = Some("k8Fy7htmvi2NG7yh".to_string()); + + println!("{quote_cited}"); + assert!(format!("{quote_cited}").contains("Quote")); + assert!(!format!("{quote_cited}").contains("+url")); + assert!(format!("{quote_cited}").contains("+citation")); + assert_eq!( + format!("{}", Token::Quote(quote_cited)), + "Tk:Quote [+citation]", + ); + + let mut quote_with_url = Quote::default(); + quote_with_url.text = "iXh0141J7B8P46Gv".to_string(); + quote_with_url.url = Some("CttVJU2IHDsjSjao".to_string()); + + println!("{quote_with_url}"); + assert!(format!("{quote_with_url}").contains("Quote")); + assert!(format!("{quote_with_url}").contains("+url")); + assert!(!format!("{quote_with_url}").contains("+citation")); + assert_eq!( + format!("{}", Token::Quote(quote_with_url)), + "Tk:Quote [+url]", + ); + + let mut quote_full = Quote::default(); + quote_full.text = "iXh0141J7B8P46Gv".to_string(); + quote_full.citation = Some("k8Fy7htmvi2NG7yh".to_string()); + quote_full.url = Some("CttVJU2IHDsjSjao".to_string()); + + println!("{quote_full}"); + assert!(format!("{quote_full}").contains("Quote")); + assert!(format!("{quote_full}").contains("+url")); + assert!(format!("{quote_full}").contains("+citation")); + assert_eq!( + format!("{}", Token::Quote(quote_full)), + "Tk:Quote [+url +citation]", + ); + } + + #[test] + fn flatten() { + assert_eq!(Quote::default().flatten(), r#""""#); + + let mut without_citation = Quote::default(); + let text = "AphyFDQHVbkOeaNw"; + without_citation.text = text.to_string(); + assert_eq!(without_citation.flatten(), format!(r#""{text}""#)); + + let without_citation_token = Token::Quote(without_citation); + assert_eq!(without_citation_token.flatten(), format!(r#""{text}""#)); + + let mut with_citation = Quote::default(); + let citation = "B35rcofYM0J7"; + with_citation.text = text.to_string(); + with_citation.citation = Some(citation.to_string()); + assert_eq!( + with_citation.flatten(), + format!(r#""{text}" -- {citation}"#) + ); + + let with_citation_token = Token::Quote(with_citation); + assert_eq!( + with_citation_token.flatten(), + format!(r#""{text}" -- {citation}"#) + ); + } + + #[test] + #[should_panic(expected = "Attempt to lex a quote directly from a lexeme")] + fn lex() { + let lexeme = Lexeme::new("z2UI", "FiCd", "rtq4"); + Quote::lex(&lexeme); + } +} diff --git a/src/syntax/content/parser/token/strike.rs b/src/syntax/content/parser/token/strike.rs index 2d98822..14b1dc4 100644 --- a/src/syntax/content/parser/token/strike.rs +++ b/src/syntax/content/parser/token/strike.rs @@ -69,5 +69,8 @@ mod tests { fn flatten() { let strike = Strike::new(false); assert_eq!(strike.flatten(), ""); + + let token = Token::Strike(strike); + assert_eq!(token.flatten(), ""); } } diff --git a/src/syntax/content/parser/token/table.rs b/src/syntax/content/parser/token/table.rs index 2eb29e3..f1dbae7 100644 --- a/src/syntax/content/parser/token/table.rs +++ b/src/syntax/content/parser/token/table.rs @@ -25,6 +25,7 @@ impl Table { } } + /// Counts the number of cells in the last row. pub fn last_row_count(&self) -> usize { if let Some(last) = self.contents.last() { last.len() @@ -37,7 +38,9 @@ impl Table { impl Parseable for Table { fn probe(lexeme: &Lexeme) -> bool { lexeme.match_char_sequence('%', '\n') } - fn lex(_lexeme: &Lexeme) -> Table { Table::default() } + fn lex(_lexeme: &Lexeme) -> Table { + panic!("Attempt to lex a table directly from a lexeme") + } fn render(&self) -> String { let mut xml = String::from("\n\n"); @@ -67,11 +70,100 @@ impl Parseable for Table { xml } - fn flatten(&self) -> String { String::default() } + fn flatten(&self) -> String { String::from("[Table]") } } impl std::fmt::Display for Table { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "Table") + let headers_width = self.headers.len(); + let contents_height = self.contents.len(); + let contents_width = self.last_row_count(); + + let mut extra = String::default(); + if headers_width > 0 && contents_height > 0 { + extra = format!( + " [{contents_width}x{contents_height} +{headers_width} headers]" + ); + } else if headers_width > 0 { + extra = format!(" [+{headers_width} headers]"); + } else if contents_height > 0 { + extra = format!(" [{contents_width}x{contents_height}]"); + } + + write!(f, "Table{extra}") + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::syntax::content::parser::Token; + + #[test] + #[should_panic(expected = "Attempt to lex a table directly from a lexeme")] + fn lex() { + let lexeme = Lexeme::new("tp0h", "rrFt", "Qouf"); + Table::lex(&lexeme); + } + + #[test] + fn flatten() { + assert_eq!(Table::default().flatten(), "[Table]"); + assert_eq!(Token::Table(Table::default()).flatten(), "[Table]"); + } + + #[test] + fn display() { + use std::string::ToString; + + let mut table = Table::default(); + table.add_header("A"); + table.add_header("B"); + table.add_header("C"); + + let table_token = Token::Table(table.clone()); + assert_eq!(format!("{table}"), format!("Table [+3 headers]")); + assert_eq!(format!("{table_token}"), format!("Tk:Table [+3 headers]")); + + table.add_row( + ["1", "2", "3"] + .iter() + .map(ToString::to_string) + .collect::>(), + ); + table.add_row( + ["4", "5", "6"] + .iter() + .map(ToString::to_string) + .collect::>(), + ); + table.add_row( + ["7", "8", "9"] + .iter() + .map(ToString::to_string) + .collect::>(), + ); + + let table_token2 = Token::Table(table.clone()); + assert_eq!(format!("{table}"), "Table [3x3 +3 headers]"); + assert_eq!(format!("{table_token2}"), "Tk:Table [3x3 +3 headers]"); + + let mut table2 = Table::default(); + table2.add_row( + ["1", "2", "3"] + .iter() + .map(ToString::to_string) + .collect::>(), + ); + table2.add_row( + ["2", "4", "6"] + .iter() + .map(ToString::to_string) + .collect::>(), + ); + + let table2_token = Token::Table(table2.clone()); + assert_eq!(format!("{table2}"), "Table [3x2]"); + assert_eq!(format!("{table2_token}"), "Tk:Table [3x2]"); } } diff --git a/src/syntax/content/parser/token/underline.rs b/src/syntax/content/parser/token/underline.rs index e8e2668..0cd565e 100644 --- a/src/syntax/content/parser/token/underline.rs +++ b/src/syntax/content/parser/token/underline.rs @@ -75,5 +75,8 @@ mod tests { fn flatten() { let underline = Underline::new(false); assert_eq!(underline.flatten(), ""); + + let token = Token::Underline(underline); + assert_eq!(token.flatten(), ""); } } diff --git a/src/syntax/content/parser/token/verse.rs b/src/syntax/content/parser/token/verse.rs index 0c0d696..f3f7910 100644 --- a/src/syntax/content/parser/token/verse.rs +++ b/src/syntax/content/parser/token/verse.rs @@ -55,6 +55,7 @@ impl std::fmt::Display for Verse { #[cfg(test)] mod tests { use super::*; + use crate::syntax::content::parser::Token; #[test] fn lexed_verse_is_empty() { @@ -63,9 +64,12 @@ mod tests { } #[test] - fn flat_verse_is_empty() { + fn flatten() { let verse = Verse::new(true); assert!(verse.flatten().is_empty()); + + let token = Token::Verse(verse); + assert_eq!(token.flatten(), ""); } #[test] @@ -80,12 +84,18 @@ mod tests { #[test] fn display() { let open = Verse::new(true); + let open_token = Token::Verse(open.clone()); assert_eq!(format!("{open}"), "Verse [open]"); + assert_eq!(format!("{open_token}"), "Tk:Verse [open]"); let closed = Verse::new(false); + let closed_token = Token::Verse(closed.clone()); assert_eq!(format!("{closed}"), "Verse [closed]"); + assert_eq!(format!("{closed_token}"), "Tk:Verse [closed]"); let unknown = Verse::lex(&Lexeme::default()); + let unknown_token = Token::Verse(unknown.clone()); assert_eq!(format!("{unknown}"), "Verse [unknown]"); + assert_eq!(format!("{unknown_token}"), "Tk:Verse [unknown]"); } } From dfddbba4ef1f6d894014f841835dcd850086d158 Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 22 Mar 2026 18:50:15 -0300 Subject: [PATCH 18/44] Embed a 'welcome' graph to fallback on --- Cargo.lock | 18 +++--- Cargo.toml | 2 +- src/graph.rs | 103 ++++++++++++++++++++++++++------ src/router/handlers/template.rs | 18 +++--- static/welcome.toml | 17 ++++++ 5 files changed, 123 insertions(+), 35 deletions(-) create mode 100644 static/welcome.toml diff --git a/Cargo.lock b/Cargo.lock index d5037d8..edb0fee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -259,7 +259,7 @@ dependencies = [ [[package]] name = "en" -version = "0.3.1-alpha" +version = "0.4.0-alpha" dependencies = [ "axum", "serde", @@ -1209,9 +1209,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdc97a28575b85cfedf2a7e7d3cc64b3e11bd8ac766666318003abbacc7a21fc" +checksum = "dea7109cdcd5864d4eeb1b58a1648dc9bf520360d7af16ec26d0a9354bafcfc0" dependencies = [ "base64", "flate2", @@ -1220,15 +1220,15 @@ dependencies = [ "rustls", "rustls-pki-types", "ureq-proto", - "utf-8", + "utf8-zero", "webpki-roots", ] [[package]] name = "ureq-proto" -version = "0.5.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d81f9efa9df032be5934a46a068815a10a042b494b6a58cb0a1a97bb5467ed6f" +checksum = "e994ba84b0bd1b1b0cf92878b7ef898a5c1760108fe7b6010327e274917a808c" dependencies = [ "base64", "http", @@ -1237,10 +1237,10 @@ dependencies = [ ] [[package]] -name = "utf-8" -version = "0.7.6" +name = "utf8-zero" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" [[package]] name = "version_check" diff --git a/Cargo.toml b/Cargo.toml index d42bdc2..bac9f33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "en" -version = "0.3.1-alpha" +version = "0.4.0-alpha" description = "A non-linear writing instrument." license = "AGPL-3.0-only" diff --git a/src/graph.rs b/src/graph.rs index 7e24eb0..67a32b5 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, path::PathBuf}; +use std::{collections::HashMap, io, path::PathBuf}; pub use edge::Edge; pub use meta::{Config, Meta}; @@ -43,6 +43,18 @@ pub struct Stats { } impl Graph { + fn welcome() -> Graph { + let toml = include_str!("../static/welcome.toml"); + let mut welcome_graph = match Graph::from_serial(toml, &Format::TOML) { + Ok(graph) => graph, + Err(error) => { + panic!("Welcome graph parsing must be infallible: {error:?}") + }, + }; + welcome_graph.modulate(); + welcome_graph + } + pub fn with_message(message: &str) -> Graph { let graph = Graph::default(); let mut messages = graph.meta.messages; @@ -69,12 +81,23 @@ impl Graph { /// Loads a Graph TOML file from CLI arguments or their defaults and /// returns a modulated Graph. /// + /// Loads a default graph with basic usage instructions if no file is found. + /// /// Returns a graph with an error message if any errors are propagated. pub fn load() -> Graph { let result = Graph::load_file(None); match result { Ok(graph) => graph, - Err(error) => Graph::malformed(Some(&error)), + Err(error) => { + if error.not_found { + return Graph::welcome() + } + if let Some(message) = error.message { + Graph::malformed(Some(&message)) + } else { + Graph::malformed(None) + } + }, } } @@ -84,7 +107,7 @@ impl Graph { /// /// # Errors /// Propagates errors from `Graph::read_file`. - pub fn load_file(path: Option<&str>) -> Result { + pub fn load_file(path: Option<&str>) -> Result { let mut graph = Graph::from_file(path)?; graph.modulate(); Ok(graph) @@ -95,21 +118,24 @@ impl Graph { /// # Errors /// Returns Err if it can't read the contents of `in_path`. /// Propagates errors from `Graph::from_serial`. - pub fn from_file(in_path: Option<&str>) -> Result { + pub fn from_file(in_path: Option<&str>) -> Result { let cli_path = Arguments::default().parse().graph_path; let path = in_path.map_or(cli_path, PathBuf::from); let toml_source = match std::fs::read_to_string(&path) { Ok(s) => s, - Err(e) => { + Err(error) => { log!( ERROR, - "Error reading path {}: {e}", + "Error reading path {}: {error}", path.as_path().display(), ); - return Err(format!( - "Failed reading file at {}", - path.as_path().display(), + return Err(LoadError::from_io_with_message( + &format!( + "Failed reading file at {}", + path.as_path().display(), + ), + error, )); }, }; @@ -489,12 +515,60 @@ impl Graph { } } +#[derive(Debug)] pub enum Format { TOML, JSON, Unsupported, } +#[derive(Debug)] +pub struct LoadError { + pub message: Option, + pub not_found: bool, + pub io_error: Option, + pub serial_error: Option, +} + +impl LoadError { + fn from_io_with_message(message: &str, io_error: io::Error) -> LoadError { + LoadError { + message: Some(String::from(message)), + not_found: io_error.kind() == io::ErrorKind::NotFound, + io_error: Some(io_error), + serial_error: None, + } + } +} + +impl From for LoadError { + fn from(error: SerialError) -> LoadError { + LoadError { + message: Some(error.message.clone()), + not_found: false, + serial_error: Some(error), + io_error: None, + } + } +} + +impl From for LoadError { + fn from(error: io::Error) -> LoadError { + LoadError { + message: Some(error.to_string()), + not_found: error.kind() == io::ErrorKind::NotFound, + io_error: Some(error), + serial_error: None, + } + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct SerialError { + pub cause: SerialErrorCause, + pub message: String, +} + #[derive(Serialize, Deserialize, Clone, Debug)] pub enum SerialErrorCause { UnsupportedFormat, @@ -511,12 +585,6 @@ impl std::fmt::Display for SerialErrorCause { } } -#[derive(Serialize, Deserialize, Clone, Debug)] -pub struct SerialError { - pub cause: SerialErrorCause, - pub message: String, -} - impl From for String { fn from(error: SerialError) -> String { format!("{}: {}", error.cause, error.message) @@ -1314,12 +1382,11 @@ mod serial_tests { use crate::dev::test::{Directories, Error}; #[test] - fn bad_graph_path() -> Result<(), Error> { + fn no_graph_fallback() -> Result<(), Error> { let _dirs = Directories::setup("bad_graph_path")?; let graph = Graph::load(); - let message = graph.meta.messages.first().unwrap(); - assert!(message.contains("Failed reading file at")); + assert_eq!(graph.nodes["GettingStarted"].title, "Getting Started"); Ok(()) } diff --git a/src/router/handlers/template.rs b/src/router/handlers/template.rs index 2fd7a83..eab2675 100644 --- a/src/router/handlers/template.rs +++ b/src/router/handlers/template.rs @@ -137,15 +137,14 @@ fn load_templates() -> Result { let root = PathBuf::from("templates"); let default_names: Vec<&str> = DEFAULTS.iter().map(|(n, _)| *n).collect(); - log!( - DEBUG, - "Reading templates from {}, canonical form {:?}", - root.display(), - root.canonicalize() - ); - match fs::read_dir(&root) { Ok(dir) => { + log!( + DEBUG, + "Reading templates from root directory '{}', canonically {:?}", + root.display(), + root.canonicalize() + ); for file_opt in dir { let file = file_opt?; let path = file.path(); @@ -168,6 +167,11 @@ fn load_templates() -> Result { } }, Err(error) => { + log!( + VERBOSE, + "A 'templates' directory was not found or is not accessible: \ + only built-in templates will be available" + ); if error.kind() != ErrorKind::NotFound { return Err(tera::Error::msg(error.to_string())) } diff --git a/static/welcome.toml b/static/welcome.toml new file mode 100644 index 0000000..7ff2d33 --- /dev/null +++ b/static/welcome.toml @@ -0,0 +1,17 @@ +[nodes.GettingStarted] +title = "Getting Started" +text = """ +## Welcome to en! +# +If you are seeing this, it's working! + +Now that you know how to run it, tell en how to find your graph file by adding a `--graph` option: + +` +en --graph my_graph.toml +` + +Alternatively, you can also add a `static` directory next to the en binary with a `graph.toml` file in it. + +To learn how to write your first graph and everything else about en, check out the |documentation|https://en.jutty.dev|. +""" From cad3213dad605f1547ef8896cf8711df5f8694da Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 22 Mar 2026 19:14:54 -0300 Subject: [PATCH 19/44] CI: Update publish workflow --- .forgejo/workflows/publish.yaml | 11 ++++++++--- .justfile | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.forgejo/workflows/publish.yaml b/.forgejo/workflows/publish.yaml index 04ab097..fc546f8 100644 --- a/.forgejo/workflows/publish.yaml +++ b/.forgejo/workflows/publish.yaml @@ -10,8 +10,7 @@ jobs: image: rust:slim steps: - name: Install action dependencies - run: | - apt-get install --no-install-recommends --update -y nodejs curl git + run: apt-get install --no-install-recommends --update -y nodejs curl git - name: Checkout code uses: actions/checkout@v6 @@ -22,13 +21,19 @@ jobs: run: | rustup component add llvm-tools-preview rustup component add --toolchain nightly rustfmt clippy + rustup target add x86_64-unknown-linux-gnu rustup target add x86_64-unknown-linux-musl - name: Setup additional tooling run: .forgejo/workflows/setup-tools.sh + - name: Setup CI user + run: | + useradd -m ci && chown -R ci:ci . + git config --global --add safe.directory "$PWD" + - name: Run all assessments - run: just verify + run: just ci verify - name: Build x64 glibc release binary run: just release-build x86_64-unknown-linux-gnu diff --git a/.justfile b/.justfile index 7c9d28a..92e5a80 100644 --- a/.justfile +++ b/.justfile @@ -360,7 +360,7 @@ alias sa := security-assess # Find TODOs [group: 'assess'] todos-assess: - ! rg -M 200 --max-columns-preview TODO src + ! grep -rn TODO src alias ta := todos-assess From d881f0bd585a34b334edca42bf26a115f0bb9aad Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 23 Apr 2026 17:54:22 -0300 Subject: [PATCH 20/44] Bump minimum Rust version to 1.94.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bac9f33..21f25fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://en.jutty.dev" documentation = "https://en.jutty.dev/node/Documentation" edition = "2024" -rust-version= "1.91.1" +rust-version= "1.94.0" [features] serial-tests = [] From 5bfd23925b530da7b9cce36aab9722be6fb44ee5 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 23 Apr 2026 17:55:21 -0300 Subject: [PATCH 21/44] Add mutation testing to justfile --- .justfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.justfile b/.justfile index 92e5a80..ac7eb3c 100644 --- a/.justfile +++ b/.justfile @@ -198,6 +198,22 @@ cover-open: alias oo := cover-open +mutate: + -just mutate-single -- --test-threads=1 serial_tests:: + -just mutate-single -- --skip serial_tests:: + +alias m := mutate + +[private] +mutate-single *cargo_test_args: + cargo mutants --iterate \ + -E ' bool' \ + --output target/mutants \ + -- {{ cargo_test_args }} + # Tag HEAD with version from Cargo.toml [script, group: 'assess'] tag commit="HEAD": update From c18b656125c4857c5de060d4382475f9827127a0 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 23 Apr 2026 18:13:47 -0300 Subject: [PATCH 22/44] Add supply chain security checks --- .justfile | 11 +- Cargo.lock | 345 ++++++++--------------------------------------------- Cargo.toml | 1 - deny.toml | 243 +++++++++++++++++++++++++++++++++++++ 4 files changed, 300 insertions(+), 300 deletions(-) create mode 100644 deny.toml diff --git a/.justfile b/.justfile index ac7eb3c..8a3acb7 100644 --- a/.justfile +++ b/.justfile @@ -204,6 +204,9 @@ mutate: alias m := mutate +deny: + cargo deny check + [private] mutate-single *cargo_test_args: cargo mutants --iterate \ @@ -345,8 +348,7 @@ verify: exit 1 fi {{ just_cmd }} \ - todos-assess version-assess \ - security-assess \ + todos-assess version-assess deny \ format-assess lint-assess check \ test "" cover-assess @@ -368,11 +370,6 @@ version-assess: update alias va := version-assess -# Audit security advisories -security-assess: - cargo audit --deny warnings -alias sa := security-assess - # Find TODOs [group: 'assess'] todos-assess: diff --git a/Cargo.lock b/Cargo.lock index edb0fee..02377cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "adler2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" - [[package]] name = "aho-corasick" version = "1.1.4" @@ -40,9 +34,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "axum" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" dependencies = [ "axum-core", "bytes", @@ -90,17 +84,11 @@ dependencies = [ "tracing", ] -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - [[package]] name = "bitflags" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "block-buffer" @@ -135,9 +123,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "cc" -version = "1.2.57" +version = "1.2.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" dependencies = [ "find-msvc-tools", "shlex", @@ -197,15 +185,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc32fast" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" -dependencies = [ - "cfg-if", -] - [[package]] name = "crossbeam-deque" version = "0.8.6" @@ -268,7 +247,6 @@ dependencies = [ "tokio", "toml", "tower", - "ureq", ] [[package]] @@ -283,16 +261,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" -[[package]] -name = "flate2" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - [[package]] name = "form_urlencoded" version = "1.2.2" @@ -382,9 +350,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" [[package]] name = "http" @@ -442,9 +410,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" dependencies = [ "atomic-waker", "bytes", @@ -456,7 +424,6 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "pin-utils", "smallvec", "tokio", ] @@ -518,9 +485,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", "hashbrown", @@ -534,9 +501,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "js-sys" -version = "0.3.91" +version = "0.3.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca" dependencies = [ "once_cell", "wasm-bindgen", @@ -550,9 +517,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.183" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "libm" @@ -584,25 +551,15 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "miniz_oxide" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" -dependencies = [ - "adler2", - "simd-adler32", -] - [[package]] name = "mio" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" dependencies = [ "libc", "wasi", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -722,12 +679,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -757,9 +708,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" dependencies = [ "libc", "rand_chacha", @@ -814,55 +765,6 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" -[[package]] -name = "ring" -version = "0.17.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "untrusted", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustls" -version = "0.23.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" -dependencies = [ - "log", - "once_cell", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" -dependencies = [ - "zeroize", -] - -[[package]] -name = "rustls-webpki" -version = "0.103.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - [[package]] name = "rustversion" version = "1.0.22" @@ -940,9 +842,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "1.0.4" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" dependencies = [ "serde_core", ] @@ -976,12 +878,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "simd-adler32" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" - [[package]] name = "siphasher" version = "1.0.2" @@ -1017,15 +913,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "2.0.117" @@ -1067,23 +957,23 @@ dependencies = [ [[package]] name = "tokio" -version = "1.50.0" +version = "1.52.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" dependencies = [ "libc", "mio", "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", @@ -1116,18 +1006,18 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.0.10+spec-1.1.0" +version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7df25b4befd31c4816df190124375d5a20c6b6921e2cad937316de3fccd63420" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" dependencies = [ - "winnow 1.0.0", + "winnow 1.0.2", ] [[package]] name = "toml_writer" -version = "1.0.7+spec-1.1.0" +version = "1.1.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17aaa1c6e3dc22b1da4b6bba97d066e354c7945cac2f7852d4e4e7ca7a6b56d" +checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" [[package]] name = "tower" @@ -1179,9 +1069,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" [[package]] name = "ucd-trie" @@ -1197,50 +1087,9 @@ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-segmentation" -version = "1.12.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "ureq" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea7109cdcd5864d4eeb1b58a1648dc9bf520360d7af16ec26d0a9354bafcfc0" -dependencies = [ - "base64", - "flate2", - "log", - "percent-encoding", - "rustls", - "rustls-pki-types", - "ureq-proto", - "utf8-zero", - "webpki-roots", -] - -[[package]] -name = "ureq-proto" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e994ba84b0bd1b1b0cf92878b7ef898a5c1760108fe7b6010327e274917a808c" -dependencies = [ - "base64", - "http", - "httparse", - "log", -] - -[[package]] -name = "utf8-zero" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" +checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" [[package]] name = "version_check" @@ -1266,9 +1115,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasm-bindgen" -version = "0.2.114" +version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89" dependencies = [ "cfg-if", "once_cell", @@ -1279,9 +1128,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.114" +version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1289,9 +1138,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.114" +version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904" dependencies = [ "bumpalo", "proc-macro2", @@ -1302,29 +1151,20 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.114" +version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129" dependencies = [ "unicode-ident", ] -[[package]] -name = "webpki-roots" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "winapi-util" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -1386,15 +1226,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -1404,70 +1235,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - [[package]] name = "winnow" version = "0.7.15" @@ -1476,36 +1243,30 @@ checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" [[package]] name = "winnow" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a90e88e4667264a994d34e6d1ab2d26d398dcdca8b7f52bec8668957517fc7d8" +checksum = "2ee1708bef14716a11bae175f579062d4554d95be2c6829f518df847b7b3fdd0" [[package]] name = "zerocopy" -version = "0.8.47" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.47" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "zeroize" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" - [[package]] name = "zmij" version = "1.0.21" diff --git a/Cargo.toml b/Cargo.toml index 21f25fb..54a54a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ serde = { version = "1.0.228", features = ["derive"] } toml = "0.9.8" [dev-dependencies] -ureq = "3" tower = { version = "0.5.2", features = ["util"] } [lints.rust] diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..3f372aa --- /dev/null +++ b/deny.toml @@ -0,0 +1,243 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# The graph table configures how the dependency graph is constructed and thus +# which crates the checks are performed against +[graph] +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #"x86_64-unknown-linux-musl", + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = false +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] + +# The output table provides options for how/if diagnostics are outputted +[output] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +# The path where the advisory databases are cloned/fetched into +#db-path = "$CARGO_HOME/advisory-dbs" +# The url(s) of the advisory databases to use +#db-urls = ["https://github.com/rustsec/advisory-db"] +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", + #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, + #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish + #{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, +] +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "MIT", + "BSD-2-Clause", + "BSD-3-Clause", + "Apache-2.0", + "Apache-2.0 WITH LLVM-exception", + "AGPL-3.0-only", + "Unicode-3.0", +] +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], crate = "adler32" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +#[[licenses.clarify]] +# The package spec the clarification applies to +#crate = "ring" +# The SPDX expression for the license requirements of the crate +#expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +#license-files = [ +# Each entry is a crate relative path, and the (opaque) hash of its contents +#{ path = "LICENSE", hash = 0xbd0eed23 } +#] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry +] + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "warn" +# Lint level for when a crate version requirement is `*` +wildcards = "allow" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overridden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overridden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is allowed" }, +] +# If true, workspace members are automatically allowed even when using deny-by-default +# This is useful for organizations that want to deny all external dependencies by default +# but allow their own workspace crates without having to explicitly list them +allow-workspace = false +# List of crates to deny +deny = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is banned" }, + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, +] + +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#crate = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason why it can't be updated/removed" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #"ansi_term@0.11.0", # will be skipped along with _all_ of its direct and transitive dependencies + #{ crate = "ansi_term@0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "warn" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "warn" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# github.com organizations to allow git sources for +github = [] +# gitlab.com organizations to allow git sources for +gitlab = [] +# bitbucket.org organizations to allow git sources for +bitbucket = [] From aab419a18a8b86fe6bd3909ab81010cec7b48ec1 Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 1 Jun 2026 14:26:42 -0300 Subject: [PATCH 23/44] Bump dependencies, add justfile comments, apply fixes --- .justfile | 11 ++- Cargo.lock | 100 ++++++++++++----------- src/syntax/content/parser/token/quote.rs | 2 +- src/syntax/content/parser/token/table.rs | 4 +- 4 files changed, 62 insertions(+), 55 deletions(-) diff --git a/.justfile b/.justfile index 8a3acb7..04f6321 100644 --- a/.justfile +++ b/.justfile @@ -198,15 +198,14 @@ cover-open: alias oo := cover-open +# Perform mutation testing +[group: 'develop'] mutate: -just mutate-single -- --test-threads=1 serial_tests:: -just mutate-single -- --skip serial_tests:: alias m := mutate -deny: - cargo deny check - [private] mutate-single *cargo_test_args: cargo mutants --iterate \ @@ -377,6 +376,12 @@ todos-assess: alias ta := todos-assess +# Check for security advisories, unexpected licenses, allowed registries +[group: 'assess'] +deny: + cargo deny check + + # BUILD # Cleanup build artifacts diff --git a/Cargo.lock b/Cargo.lock index 02377cd..21ada32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,9 +28,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "axum" @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.20.2" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" [[package]] name = "bytes" @@ -123,9 +123,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "cc" -version = "1.2.60" +version = "1.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" +checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" dependencies = [ "find-msvc-tools", "shlex", @@ -350,15 +350,15 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" [[package]] name = "http" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0" dependencies = [ "bytes", "itoa", @@ -410,9 +410,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.9.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" +checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498" dependencies = [ "atomic-waker", "bytes", @@ -501,10 +501,12 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "js-sys" -version = "0.3.95" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" dependencies = [ + "cfg-if", + "futures-util", "once_cell", "wasm-bindgen", ] @@ -529,9 +531,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "log" -version = "0.4.29" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" [[package]] name = "matchit" @@ -541,9 +543,9 @@ checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" [[package]] name = "memchr" -version = "2.8.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" [[package]] name = "mime" @@ -553,9 +555,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mio" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" dependencies = [ "libc", "wasi", @@ -818,9 +820,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.149" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ "itoa", "memchr", @@ -874,15 +876,15 @@ dependencies = [ [[package]] name = "shlex" -version = "1.3.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "siphasher" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" +checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649" [[package]] name = "slab" @@ -908,9 +910,9 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" dependencies = [ "libc", "windows-sys", @@ -957,9 +959,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.52.1" +version = "1.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" dependencies = [ "libc", "mio", @@ -1010,7 +1012,7 @@ version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" dependencies = [ - "winnow 1.0.2", + "winnow 1.0.3", ] [[package]] @@ -1069,9 +1071,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.20.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "ucd-trie" @@ -1087,9 +1089,9 @@ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-segmentation" -version = "1.13.2" +version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" [[package]] name = "version_check" @@ -1115,9 +1117,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasm-bindgen" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" dependencies = [ "cfg-if", "once_cell", @@ -1128,9 +1130,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1138,9 +1140,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" dependencies = [ "bumpalo", "proc-macro2", @@ -1151,9 +1153,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" dependencies = [ "unicode-ident", ] @@ -1243,24 +1245,24 @@ checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" [[package]] name = "winnow" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ee1708bef14716a11bae175f579062d4554d95be2c6829f518df847b7b3fdd0" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" [[package]] name = "zerocopy" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639" dependencies = [ "proc-macro2", "quote", diff --git a/src/syntax/content/parser/token/quote.rs b/src/syntax/content/parser/token/quote.rs index 397b41f..81d5544 100644 --- a/src/syntax/content/parser/token/quote.rs +++ b/src/syntax/content/parser/token/quote.rs @@ -40,7 +40,7 @@ impl Parseable for Quote { let content = if let Some(citation) = &self.citation { format!( r#"{}
{citation}"#, - &self.text + self.text ) } else { String::from(&self.text) diff --git a/src/syntax/content/parser/token/table.rs b/src/syntax/content/parser/token/table.rs index f1dbae7..ab2f715 100644 --- a/src/syntax/content/parser/token/table.rs +++ b/src/syntax/content/parser/token/table.rs @@ -122,8 +122,8 @@ mod tests { table.add_header("C"); let table_token = Token::Table(table.clone()); - assert_eq!(format!("{table}"), format!("Table [+3 headers]")); - assert_eq!(format!("{table_token}"), format!("Tk:Table [+3 headers]")); + assert_eq!(format!("{table}"), "Table [+3 headers]"); + assert_eq!(format!("{table_token}"), "Tk:Table [+3 headers]"); table.add_row( ["1", "2", "3"] From 29c2beb3ed0aa6077b5585dd7ca1fda627175440 Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 1 Jun 2026 16:07:26 -0300 Subject: [PATCH 24/44] Update docs for latest version, add more pointers across starting pages --- static/graph.toml | 70 +++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/static/graph.toml b/static/graph.toml index a4782ae..2b898e0 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -1,4 +1,28 @@ -root_node = "Documentation" +root_node = "Start" + +[nodes.Start] +text = """ +en is a writing tool. It was designed with complex, inter-connected projects in mind where the relationships between concepts matter. You can use to write non-linear, connected pieces of text and have their references mapped out as a |graph| of metadata-rich, connected information. + +It works by ingesting |TOML| files containing your node specifications and serving it as a human-readable website that allows nodes to be browsed, searched and listed in relation to each other or as a shallow tree of nodes. It also serves this node as raw data for integration with other tools that can then further transform what you have written. + +## Motivation + +en was created out of the desire to write complex, long-form descriptions of a personal worldview without being constrained or getting stuck trying to mimic the linearity of a typical philosophy book. + +It's described as a "writing instrument" because it's not so much about the presentation or even the web format. While that's the medium for this particular implementation, you can notice en serves its raw data in both TOML and JSON. It's first and foremost about mapping out and structuring written thoughts. + +Because en is defined in simple configuration files, you can add new pages easily from a few lines and start connecting them. Instead of having to create a dedicated file or resource for each new entry you find deserving of observation, with its own beginning and end, its own "I'm empty, fill me to completion" demeanor, you can stay in the flow of your sprawling thoughts. This is meant to fit the specific wiring of minds whose thoughts spread and fork quickly and often, whether to great depth or across wide expanses. + +## Get started + +- Check the |docs| to learn how to install and use en +- Read about the |syntax| used to create nodes +- Glimpse into en's future in the |roadmap| +- Visit the |data endpoints|/data| for a raw view of this very graph +- Look under the hood in the |source code|https://codeberg.org/jutty/en repo +- See an index of all pages in the |tree|/tree| +""" [nodes.Documentation] text = """ @@ -71,6 +95,8 @@ The main electronic component of a computer is its |motherboard|. \""" ` +In |the future|Roadmap, en should support both individual node files with TOML frontmatter and also multiple TOML files containing several nodes each. In the current implementation, all nodes live in a single `graph.toml` file. + Some special syntax is allowed inside the node text. See |Syntax| for supported features. A node can have several other attributes. See |Node| for details on all of them. @@ -94,20 +120,27 @@ Even if a node is not mentioned in the node text, you can still add connections [nodes.Quark] text = "A subatomic particle that forms hadrons." -links = [ "Particle", "Hadron" ] -` +links = [ "Particle", "Hadron" ] ` This will create two outgoing connections from Quark: to Particle and to Hadron. -For metadata-rich connections, which allow you to add properties to the connection, you can use the full connection syntax: +For richer connections that have their own properties, you can use the full connection syntax: ` -[[nodes.Realism.connections]] -to = "Surrealism" -kind = "contrast" +[nodes.Earth.connections.Moon] +kind = "Satellite" + +[nodes.Earth.connections.MilkyWay] +kind = "Galaxy" ` -This will create a connection from the node with ID `Realism` to a node with ID `Surrealism` and add the "contrast" kind to the connection. See |Connections| for the existing kinds and how they affect your graph. +This will create connections from the node with ID `Earth` to the nodes with ID `Moon` and `MilkyWay` and add the "Satellite" and "Galaxy" kinds to each connection, respectively. This can be used to render connections in special ways and is reflected in the |outputs|. + +## Where to go from here + +en is in its infancy. If you are curious, you can download it and try it by using the |Syntax| docs as a reference or build the |SourceBuild|latest version| yourself to see what's new. Your bug reports are much appreciated. + +If you like what you see and are curious about en's future, take a look at the |roadmap| for a peek into what's to come. """ [nodes.docs] @@ -612,6 +645,10 @@ If you need some more advanced feature that is not supported directly by en's ma Notice that, as shown in this example, you can mix en syntax and HTML. You might want to add a space between your HTML tags and en special syntax so the boundary is clearer, but otherwise they don't tend to overlap since the symbols most used in HTML are not special in en with the exception of `<`, which is interpreted specially only at the end of lines. If you want to avoid either one of these syntaxes from being interpreted specially, you should escape the relevant characters as explained in the previous section. + +## Known issues + +- Nesting multiple different formatting symbols is currently supported only in a few cases. Better nesting is on the |roadmap|, but currently may not work as expected. """ [nodes.Escaping] @@ -748,21 +785,6 @@ en must differentiate node anchors from outgoing URLs: It does this by looking at the destination and checking if it contains a `:`. That's one more reason to avoid this character in your node IDs. """ -[nodes.en] -text = """ -en is a tool to write non-linear, connected pieces of text and have their references mapped out as a |graph| of connected information. - -It works by ingesting a |TOML| file containing your node specification and serving it as a website that allows nodes to be browsed, searched and listed in relation to each other or as a shallow tree of nodes. - -## Motivation - -en was created out of the desire to write complex, long-form descriptions of a personal worldview without being constrained or getting stuck trying to mimic the linearity of a typical philosophy book. - -It's described as a "writing instrument" because it's not so much about the presentation or even the web format. While that's the medium for this particular implementation, you can notice en serves its raw data in both TOML and JSON. It's first and foremost about mapping out and structuring written thoughts. - -Because en is defined in simple configuration files, you can add new pages easily from a few lines and start connecting them. Instead of having to create a dedicated file or resource for each new entry you find deserving of observation, with its own beginning and end, its own "I'm empty, fill me to completion" demeanor, you can stay in the flow of your sprawling thoughts. This is meant to fit the specific wiring of minds whose thoughts spread and fork quickly and often, whether to great depth or across wide expanses. -""" - [nodes.Graph] text = """ A graph is a data structure composed of connected (and disconnected) nodes. @@ -829,6 +851,7 @@ text = """ - [x] Further centralize state - [ ] Reduce O(n) calls in the formats module - [ ] Input syntax + - [ ] Improve nested formatting - [ ] Invert where redirects are set - [x] Formatting - [x] Blockquotes @@ -915,6 +938,7 @@ text = """ - See: |https://keats.github.io/tera/docs/#whitespace-control| - [ ] Full-text search - [ ] Assess Option return types that should be Result +- [ ] Consider printing parsing errors to console by default ## Done From d0ca4e6cb38c1544920b7bd6abea0bbf946e2b21 Mon Sep 17 00:00:00 2001 From: jutty Date: Tue, 2 Jun 2026 16:00:40 -0300 Subject: [PATCH 25/44] Add a context parser for PreFormat blocks --- Cargo.lock | 10 +-- Cargo.toml | 2 +- src/syntax/content/parser/context.rs | 31 ++++---- src/syntax/content/parser/context/block.rs | 44 ++++------- .../content/parser/context/preformat.rs | 61 +++++++++++++++ src/syntax/content/parser/lexeme.rs | 5 ++ src/syntax/content/parser/lexer.rs | 4 +- src/syntax/content/parser/state.rs | 8 +- src/syntax/content/parser/token/preformat.rs | 76 ++++++++----------- 9 files changed, 146 insertions(+), 95 deletions(-) create mode 100644 src/syntax/content/parser/context/preformat.rs diff --git a/Cargo.lock b/Cargo.lock index 21ada32..2d09c10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,9 +86,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.11.1" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" +checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a" [[package]] name = "block-buffer" @@ -238,7 +238,7 @@ dependencies = [ [[package]] name = "en" -version = "0.4.0-alpha" +version = "0.4.1-alpha" dependencies = [ "axum", "serde", @@ -531,9 +531,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "log" -version = "0.4.30" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" +checksum = "113b30b4cd05f7c06868fdb2854f66a7b9fece9a48425351cd532e810d74024f" [[package]] name = "matchit" diff --git a/Cargo.toml b/Cargo.toml index 54a54a0..130e36b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "en" -version = "0.4.0-alpha" +version = "0.4.1-alpha" description = "A non-linear writing instrument." license = "AGPL-3.0-only" diff --git a/src/syntax/content/parser/context.rs b/src/syntax/content/parser/context.rs index e5010f6..e1379a5 100644 --- a/src/syntax/content/parser/context.rs +++ b/src/syntax/content/parser/context.rs @@ -1,12 +1,13 @@ use crate::syntax::content::parser::{ State, Token, - token::{Header, Paragraph, PreFormat, Verse}, + token::{Header, Paragraph, Verse}, }; pub mod anchor; pub mod block; pub mod inline; pub mod list; +pub mod preformat; pub mod quote; pub mod table; @@ -38,30 +39,32 @@ pub enum Inline { } /// # Panics -/// Panics if there is an open header or list at end of input. +/// Panics if there is an open token at end of input that can't be easily +/// closed by simply adding a matching closing token. This normally is handled +/// by context parsers and probably indicates an error in one of them. pub fn close(state: &State, tokens: &mut Vec) { match state.context.block { - Block::PreFormat => { - tokens.push(Token::PreFormat(PreFormat::new(false))); - }, Block::Paragraph => { tokens.push(Token::Paragraph(Paragraph::new(false))); }, - Block::List => { - panic!("End of input with open list") - }, Block::Header(level) => { tokens.push(Token::Header(Header::from_u8(level, false, None))); }, - Block::Quote => { - panic!("End of input with open quote") - }, - Block::Table => { - panic!("End of input with open table") - }, Block::Verse => { tokens.push(Token::Verse(Verse::new(false))); }, + Block::PreFormat => { + panic!("End of input with open preformat: {tokens:#?}") + }, + Block::List => { + panic!("End of input with open list: {tokens:#?}") + }, + Block::Quote => { + panic!("End of input with open quote: {tokens:#?}") + }, + Block::Table => { + panic!("End of input with open table: {tokens:#?}") + }, Block::None => (), } } diff --git a/src/syntax/content/parser/context/block.rs b/src/syntax/content/parser/context/block.rs index 3b34724..8048896 100644 --- a/src/syntax/content/parser/context/block.rs +++ b/src/syntax/content/parser/context/block.rs @@ -6,15 +6,17 @@ use crate::{ syntax::content::{ Parseable as _, parser::{ - Block, Lexeme, State, Token, + Block, Lexeme, State, Token, context, token::{ - Header, LineBreak, List, Literal, Paragraph, PreFormat, Quote, - Table, Verse, + Header, LineBreak, List, Paragraph, PreFormat, Quote, Table, + Verse, }, }, }, }; +/// A return of `true` will trigger a `continue` on the outer parser, causing +/// no more subsequent parsing of the current lexeme. pub fn parse( lexeme: &Lexeme, state: &mut State, @@ -27,8 +29,7 @@ pub fn parse( if PreFormat::probe(lexeme) { log!(VERBOSE, "Block Context: None -> PreFormat on {lexeme}"); state.context.block = Block::PreFormat; - tokens.push(Token::PreFormat(PreFormat::new(true))); - return true; + return true } else if Header::probe(lexeme) { let mut header = Header::lex(lexeme); header.dom_id = Some(Header::make_id( @@ -44,7 +45,7 @@ pub fn parse( log!(VERBOSE, "Block Context: None -> List on {lexeme}"); state.context.block = Block::List; state.buffers.list.candidate.ordered = lexeme.match_char('+'); - return super::list::parse( + return context::list::parse( lexeme, state, tokens, iterator, graph, ); } else if Quote::probe(lexeme) { @@ -71,14 +72,7 @@ pub fn parse( } }, Block::PreFormat => { - if PreFormat::probe(lexeme) { - tokens.push(Token::PreFormat(PreFormat::new(false))); - log!(VERBOSE, "Block Context: PreFormat -> None on {lexeme}"); - state.context.block = Block::None; - } else { - tokens.push(Token::Literal(Literal::lex(lexeme))); - } - return true; + return context::preformat::parse(lexeme, state, tokens, iterator); }, Block::Paragraph => { if Paragraph::probe_end(lexeme) { @@ -95,13 +89,17 @@ pub fn parse( } }, Block::List => { - return super::list::parse(lexeme, state, tokens, iterator, graph); + return context::list::parse(lexeme, state, tokens, iterator, graph); }, Block::Quote => { - return super::quote::parse(lexeme, state, tokens, iterator, graph); + return context::quote::parse( + lexeme, state, tokens, iterator, graph, + ); }, Block::Table => { - return super::table::parse(lexeme, state, tokens, iterator, graph); + return context::table::parse( + lexeme, state, tokens, iterator, graph, + ); }, Block::Verse => { if Verse::probe_end(lexeme) { @@ -127,7 +125,7 @@ mod tests { graph::Graph, syntax::content::parser::{ self, Block, State, Token, context, - token::{Header, PreFormat, header::Level}, + token::{Header, header::Level}, }, }; @@ -161,16 +159,6 @@ mod tests { assert_eq!(vec, vec![Token::Header(Header::from_u8(1, false, None))]); } - #[test] - fn end_with_open_preformat() { - let mut state = State::default(); - state.context.block = Block::PreFormat; - - let mut vec: Vec = vec![]; - context::close(&state, &mut vec); - assert_eq!(vec, vec![Token::PreFormat(PreFormat::new(false))]); - } - #[test] fn truncated_header_level() { let u: usize = 999; diff --git a/src/syntax/content/parser/context/preformat.rs b/src/syntax/content/parser/context/preformat.rs new file mode 100644 index 0000000..ed6763f --- /dev/null +++ b/src/syntax/content/parser/context/preformat.rs @@ -0,0 +1,61 @@ +use std::{iter::Peekable, slice::Iter}; + +use crate::{ + prelude::*, + syntax::content::{ + Parseable as _, + parser::{Lexeme, State, Token, context::Block, token::PreFormat}, + }, +}; + +/// Handles open `PreFormat` contexts until a block is fully parsed. +/// +/// A return of `true` will trigger a continue in the outer parser, +/// skipping any further parsing of the current lexeme. +/// +/// # Panics +/// This parser can handle only the List context, and will panic if passed an +/// unrelated context since it has no knowledge on how to handle them. +pub fn parse( + lexeme: &Lexeme, + state: &mut State, + tokens: &mut Vec, + iterator: &mut Peekable>, +) -> bool { + let buffer = &mut state.buffers.preformat; + let candidate = &mut buffer.candidate; + + #[expect(clippy::wildcard_enum_match_arm)] + match state.context.block { + Block::PreFormat => { + if lexeme.match_first_char('<') { + candidate.text.push_str("<"); + candidate.text.push_str( + lexeme.text().strip_prefix('<').unwrap_or(&lexeme.text()), + ); + } else if lexeme.match_last_char('>') { + candidate.text.push_str( + lexeme.text().strip_suffix('>').unwrap_or(&lexeme.text()), + ); + candidate.text.push_str(">"); + } else if lexeme.match_char('\\') { + candidate.text.push_str(lexeme.next().as_str()); + iterator.next(); + return true; + } else if PreFormat::probe(lexeme) { + // found end of block, push it and reset state + log!(VERBOSE, "Accepting preformat candidate {candidate}"); + tokens.push(Token::PreFormat(candidate.clone())); + state.context.block = Block::None; + *candidate = PreFormat::default(); + } else { + // anything else is pushed into the candidate preformat's text + candidate.text.push_str(&lexeme.text()); + } + }, + _ => { + panic!("PreFormat context parser called for {:?}", state.context) + }, + } + true +} diff --git a/src/syntax/content/parser/lexeme.rs b/src/syntax/content/parser/lexeme.rs index 495b27b..94b28d5 100644 --- a/src/syntax/content/parser/lexeme.rs +++ b/src/syntax/content/parser/lexeme.rs @@ -32,6 +32,8 @@ impl Lexeme { pub fn mutate_text(&mut self, new: &str) { self.text = new.to_string(); } + /// Returns an Option containing the character if the raw lexeme text + /// is composed of a single character, None if it has multiple characters. pub fn as_char(&self) -> Option { if self.text.chars().count() == 1 { self.text.chars().nth(0) @@ -56,6 +58,7 @@ impl Lexeme { } } + /// Returns true if the raw lexeme text is a single matching character. pub fn match_char(&self, c: char) -> bool { self.as_char().is_some_and(|as_char| as_char == c) } @@ -86,6 +89,8 @@ impl Lexeme { && self.match_third_char(c3) } + /// Returns true if the lexeme raw text is composed of a single character + /// and this character is in the provided slice. pub fn match_char_in(&self, slice: &[char]) -> bool { self.as_char().is_some_and(|c| slice.contains(&c)) } diff --git a/src/syntax/content/parser/lexer.rs b/src/syntax/content/parser/lexer.rs index e9a0d40..e8d3abc 100644 --- a/src/syntax/content/parser/lexer.rs +++ b/src/syntax/content/parser/lexer.rs @@ -38,7 +38,9 @@ pub(super) fn lex( let mut iterator = lexemes.iter().peekable(); while let Some(lexeme) = iterator.next() { - if lexeme.match_char('\\') { + if lexeme.match_char('\\') + && !matches!(state.context.block, context::Block::PreFormat) + { if let Some(next) = iterator.next() { tokens.push(Token::Literal(Literal::lex(next))); } diff --git a/src/syntax/content/parser/state.rs b/src/syntax/content/parser/state.rs index aa42f68..47498a3 100644 --- a/src/syntax/content/parser/state.rs +++ b/src/syntax/content/parser/state.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use crate::syntax::content::parser::{ Token, context::Context, - token::{Anchor, Item, List, Quote, Table}, + token::{Anchor, Item, List, PreFormat, Quote, Table}, }; #[derive(Clone, Default, Debug)] @@ -29,6 +29,7 @@ pub struct Buffers { pub list: ListBuffer, pub quote: QuoteBuffer, pub table: TableBuffer, + pub preformat: PreFormatBuffer, } #[derive(Default, Clone, Debug)] @@ -59,6 +60,11 @@ pub struct TableBuffer { pub in_header: bool, } +#[derive(Default, Clone, Debug)] +pub struct PreFormatBuffer { + pub candidate: PreFormat, +} + impl std::fmt::Display for AnchorBuffer { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let display_text = if self.text.is_empty() { diff --git a/src/syntax/content/parser/token/preformat.rs b/src/syntax/content/parser/token/preformat.rs index d950590..f24bbc4 100644 --- a/src/syntax/content/parser/token/preformat.rs +++ b/src/syntax/content/parser/token/preformat.rs @@ -1,46 +1,42 @@ use crate::syntax::content::{Lexeme, Parseable}; -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Clone, Eq, PartialEq)] pub struct PreFormat { - open: Option, + pub text: String, } impl PreFormat { - pub const fn new(open: bool) -> PreFormat { PreFormat { open: Some(open) } } + pub fn new(text: &str) -> PreFormat { + PreFormat { + text: String::from(text), + } + } } impl std::fmt::Display for PreFormat { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - let display_open_state = if let Some(open_state) = self.open { - if open_state { "open" } else { "closed" } + let character_count = self.text.chars().count(); + let is_whitespace = self.text.trim_ascii().is_empty(); + let summary = if is_whitespace { + "empty" } else { - "unknown" + &format!("{character_count} chars") }; - write!(f, "PreFormat [{display_open_state}]") + write!(f, "PreFormat [{summary}]") } } impl Parseable for PreFormat { fn probe(lexeme: &Lexeme) -> bool { - lexeme.match_first_char('`') && (lexeme.next() == "\n" || lexeme.last()) + lexeme.match_char('`') && (lexeme.next() == "\n" || lexeme.last()) } - fn lex(_lexeme: &Lexeme) -> PreFormat { PreFormat { open: None } } - - fn render(&self) -> String { - if let Some(o) = self.open { - if o { - "
".to_owned()
-            } else {
-                "
".to_owned() - } - } else { - panic!( - "Attempt to render a preformat tag while open state is unknown" - ) - } + fn lex(_lexeme: &Lexeme) -> PreFormat { + panic!("Attempt to lex a preformat directly from a lexeme") } + fn render(&self) -> String { format!("
{}
", self.text) } + fn flatten(&self) -> String { String::default() } } @@ -50,49 +46,39 @@ mod tests { use crate::syntax::content::parser::Token; #[test] + #[should_panic( + expected = "Attempt to lex a preformat directly from a lexeme" + )] fn lex() { - let from_empty_lexeme = PreFormat::lex(&Lexeme::default()); - assert!(from_empty_lexeme.open.is_none()); - - let from_non_empty_lexeme = PreFormat::lex(&Lexeme::default()); - assert!(from_non_empty_lexeme.open.is_none()); - } - - #[test] - #[should_panic(expected = "Attempt to render a preformat tag while \ - open state is unknown")] - fn render() { - let from_empty_lexeme = PreFormat::lex(&Lexeme::default()); - from_empty_lexeme.render(); - - let from_non_empty_lexeme = PreFormat::lex(&Lexeme::default()); - from_non_empty_lexeme.render(); + let lexeme = Lexeme::new("a", "b", "c"); + PreFormat::lex(&lexeme); } #[test] fn token_display() { - let mut preformat = PreFormat::new(true); + let mut preformat = PreFormat::new(""); + assert_eq!( format!("{}", Token::PreFormat(preformat.clone())), - "Tk:PreFormat [open]" + "Tk:PreFormat [empty]" ); - preformat.open = Some(false); + preformat.text = "\n ".to_string(); assert_eq!( format!("{}", Token::PreFormat(preformat.clone())), - "Tk:PreFormat [closed]" + "Tk:PreFormat [empty]" ); - preformat.open = None; + preformat.text = "text".to_string(); assert_eq!( format!("{}", Token::PreFormat(preformat)), - "Tk:PreFormat [unknown]" + "Tk:PreFormat [4 chars]" ); } #[test] fn flatten() { - let preformat = PreFormat::new(false); + let preformat = PreFormat::new(""); assert_eq!(preformat.flatten(), ""); let token = Token::PreFormat(preformat); From 8100b1ba109972f4d32dbf1ffe16a5278bf599de Mon Sep 17 00:00:00 2001 From: jutty Date: Tue, 2 Jun 2026 23:46:05 -0300 Subject: [PATCH 26/44] Tone down code styles --- static/public/assets/style.css | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/static/public/assets/style.css b/static/public/assets/style.css index 8242120..d3ef9b5 100644 --- a/static/public/assets/style.css +++ b/static/public/assets/style.css @@ -46,30 +46,25 @@ pre { transition: 1000ms; } -pre:hover { - box-shadow: 1px 1px 3px 2.5px #00777777; -} - code { padding: 3px 6px; margin-right: 3px; white-space: nowrap; - font-size: calc(var(--base-font-size) * 0.8); - box-shadow: 1px 1px 1px 1px #00000077; transition: 1000ms; -} - -code:hover { - box-shadow: 1px 1px 1px 1px #00777799; + box-shadow: 1px 1px 0.5px 0.5px #00000077; } pre, code { background: light-dark(#e0e0e0, #333); font-family: mono, monospace; - border: solid 2px light-dark(#d0d0d0, #434343); + border: solid 1px light-dark(#d0d0d0, #434343); border-radius: 6px; } +h1 , h2 , h3 , h4 , h5 , h6 { + code { font-size: calc(var(--base-font-size) * 0.6); } +} + a { color: light-dark(#0f6366, #1dd7d7); text-decoration: underline dotted #159b9b; @@ -100,8 +95,7 @@ a.external { } a.external:hover { - color: light-dark(#0393b2, #74e5ff); - text-decoration-color: light-dark(#1ed4f1, #aeffff); + color: light-dark(#037cb2, #74e5ff); transition: 1500ms; } @@ -150,7 +144,7 @@ span.id-label { border: solid 1px light-dark(#d0d0d0, #666); } -span.hidden-label { +span.unlisted-label { background: light-dark(#888, #000); color: light-dark(#eee, #969696); border: solid 1px light-dark(#d0d0d0, #555); From 0d48291d5fac2476feeaa0ded8d9fd9e07f95cd6 Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 3 Jun 2026 09:15:35 -0300 Subject: [PATCH 27/44] Draft a JSON schema for graphs --- static/graph-schema.json | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 static/graph-schema.json diff --git a/static/graph-schema.json b/static/graph-schema.json new file mode 100644 index 0000000..bbf6cc3 --- /dev/null +++ b/static/graph-schema.json @@ -0,0 +1,80 @@ +{ + "$id": "https://git.jutty.dev/jutty/en/raw/branch/main/static/graph-schema.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Graph", + "description": "An en graph file", + "type": "object", + "$defs": { + "node": { + + } + }, + "properties": { + "root_node": { + "type": "string", + "title": "Root node ID", + "description": "The ID of node highlighted in the homepage as the graph root.", + "example": "MyNode", + "default": null + }, + "nodes": { + "title": "Nodes", + "description": "The graph's nodes.", + "default": null, + "type": "object", + "additionalProperties": { + "type": "object", + "title": "Node", + "description": "A node object.", + "example": "[nodes.Earth]\ntext = \"Earth is a planet of the solar system.\"", + "default": null, + "properties": { + "text": { + "type": "string", + "description": "The text content of this node." + }, + "title": { + "type": "string", + "description": "The node display title, useful to make it distinct from the ID.", + "default": "The node's ID." + }, + "listed": { + "type": "boolean", + "description": "Whether this node is shown in listing pages.", + "default": true + }, + "redirect": { + "type": "string", + "description": "A node ID to where any requests for this node will be redirected.", + "default": null + } + }, + "additionalProperties": false + }, + "propertyNames": { + "pattern": "^[^-][^!@#$%^&*;:/~| \\]\\[()\\\\]*$" + } + }, + "meta": { + "type": "object", + "properties": { + "config": { + "type": "object", + "properties": { + "content_language": { "type": "string" }, + "footer_credits": { "type": "boolean" }, + "error_poem": { "type": "boolean" }, + "node_selector": { "type": "boolean" }, + "navbar_search": { "type": "boolean" }, + "about": { "type": "boolean" }, + "footer_text": { "type": "string" }, + "acknowledgments": { "type": "string" } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false +} From ab9b587018e03484f67febcaf38f2c11413d1e25 Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 3 Jun 2026 14:35:50 -0300 Subject: [PATCH 28/44] Rename 'hidden' node option to 'listed' --- src/graph.rs | 2 +- src/graph/node.rs | 17 ++++++++++------- src/router/handlers/graph.rs | 2 +- templates/base.html | 4 ++-- templates/index.html | 2 +- templates/node.html | 2 +- templates/tree.html | 4 ++-- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index 67a32b5..0fd940c 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -665,7 +665,7 @@ mod tests { "title": "JSON", "links": [], "id": "JSON", - "hidden": false, + "listed": true, "connections": {} } }, diff --git a/src/graph/node.rs b/src/graph/node.rs index ff0c719..3472641 100644 --- a/src/graph/node.rs +++ b/src/graph/node.rs @@ -18,8 +18,8 @@ pub struct Node { pub links: Vec, #[serde(default)] pub redirect: String, - #[serde(default)] - pub hidden: bool, + #[serde(default = "mktrue")] + pub listed: bool, #[serde(default)] pub connections: HashMap, @@ -28,6 +28,9 @@ pub struct Node { pub stats: Stats, } +// See: https://github.com/serde-rs/serde/issues/368 +const fn mktrue() -> bool { true } + #[derive(Serialize, Deserialize, Clone, Default, Eq, PartialEq, Debug)] pub struct Stats { pub outgoing: u32, @@ -46,7 +49,7 @@ impl Node { connections: HashMap::default(), links: vec![], redirect: String::default(), - hidden: false, + listed: true, summary: String::default(), stats: Stats::default(), } @@ -78,8 +81,8 @@ impl std::fmt::Display for Node { meta_elements.push(format!("links:{links}")); } - if self.hidden { - meta_elements.push(String::from("hidden")); + if !self.listed { + meta_elements.push(String::from("unlisted")); } let meta = meta_elements.join(" "); @@ -143,7 +146,7 @@ mod tests { ) ); - node.hidden = true; + node.listed = false; assert_eq!( format!("{node}"), @@ -153,7 +156,7 @@ mod tests { text:15l summary:{} \ redirect:{redirect} \ links:{} \ - hidden\ + unlisted\ ]", summary.len(), node.links.len(), diff --git a/src/router/handlers/graph.rs b/src/router/handlers/graph.rs index bf0b112..0ebc539 100644 --- a/src/router/handlers/graph.rs +++ b/src/router/handlers/graph.rs @@ -93,7 +93,7 @@ mod tests { #[tokio::test] async fn docs_redirect() { - let response = wrap_node("docs").await; + let response = wrap_node("RedirectTest").await; assert_eq!(response.status(), StatusCode::PERMANENT_REDIRECT); } diff --git a/templates/base.html b/templates/base.html index 990f779..61043bd 100644 --- a/templates/base.html +++ b/templates/base.html @@ -52,8 +52,8 @@
- Detached edges + Detached connections - {{ detached_count }} + {{ detached_count }}
-

Detached edges

+

Detached connections

+

These are the destinations to which connections exist, but the target node doesn't.

Expand to see all detached edges. From 70bdba50c8f49ba66fa48147f2eaa2ffc06f9d2f Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 10:27:59 -0300 Subject: [PATCH 31/44] Spell check docs --- static/graph.toml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/static/graph.toml b/static/graph.toml index 488f8e5..23bba0b 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -6,9 +6,9 @@ root_node = "Start" text = """ ## What is en? -en is a writing tool. It was designed with complex, conceptually heavy projects in mind where the relationships between terms matter and possibly have their own attributes. You can use it to write non-linear, connected textual works and have their references to which other mapped out as a |graph| of metadata-rich, interrelated information. This very website is running en. +en is a writing tool. It was designed with complex, conceptually heavy projects, where the relationships between terms matter and possibly have their own attributes. You can use it to write non-linear, connected textual works and have their references to which other mapped out as a |graph| of metadata-rich, interrelated information. This very website is running en. -It works by ingesting plain text files written in |TOML|, a file format that focuses on being human-readable but that can also be directly interpreted by computer programs. These files contain your node definitions and allow en to construct a human-readable website that makes your graphs' nodes browseable, searcheable and listed in relation to each other or as a shallow tree of nodes. It also serves this graph as raw data for integration with other tools that can further analyze and transform what you have written. +It works by ingesting plain text files written in |TOML|, a file format that focuses on being human-readable but that can also be directly interpreted by computer programs. These files contain your node definitions and allow en to construct a human-readable website that makes your graphs' nodes browsable, searchable and listed in relation to each other or as a shallow tree of nodes. It also serves this graph as raw data for integration with other tools that can further analyze and transform what you have written. ## Motivation @@ -175,7 +175,7 @@ This will create connections from the node with ID `Earth` to the nodes with ID text = """ en take as its input one or more graph files containing your node definitions. It then processes your graph, looks for connections and configuration values and produces one or more outputs depending on your settings: -- A browseable, live-served website (such as this one) +- A browsable, live-served website (such as this one) - A |TOML| representation of the graph that can be used as a basis to generate other, adapted graphs - A JSON representation of the graph that can be further analyzed and interpreted with third-party tools @@ -685,7 +685,7 @@ Finally, you can precede any character with a `\\\\` to fully _escape_ that char ## Raw HTML -If you need some more advanced feature that is not supported directly by en's markup snytax, you can always just write plain HTML and it will be passed along. For example, you could render a form: +If you need some more advanced feature that is not supported directly by en's markup syntax, you can always just write plain HTML and it will be passed along. For example, you could render a form: ` <form style="text-align: center;"> @@ -814,7 +814,7 @@ If you write a node anchor with spaces, it will be collapsed: This |Node Anchor| will work as if it were |NodeAnchor|. ` -Accordingly, node IDs should not have spaces because, among other things, this feature makes it impossible to create an achor to them. +Accordingly, node IDs should not have spaces because, among other things, this feature makes it impossible to create an anchor to them. ## Case-insensitive fallbacks @@ -1072,4 +1072,3 @@ about = true footer_text = """ acknowledgments|Acknowledgments • |source code|https://codeberg.org/jutty/en """ - From 8649169baee858fc4b4d3634c8e54400c89eaf04 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 10:28:13 -0300 Subject: [PATCH 32/44] Add CSS to watchexec extensions --- .justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.justfile b/.justfile index 04f6321..28649d6 100644 --- a/.justfile +++ b/.justfile @@ -468,7 +468,7 @@ default_target := musl_target debug_vars := 'DEBUG=${DEBUG:-} DEBUG_FILTER=${DEBUG_FILTER:-} RUST_BACKTRACE=${RUST_BACKTRACE:-} RUSTFLAGS=${RUSTFLAGS:-}' just_cmd := 'just --timestamp --explain --command-color green' just_cmd_no_ts := 'just --explain --command-color green' -watch_cmd := "watchexec -qc -r -e rs,toml,html --color always -- " +watch_cmd := "watchexec -qc -r -e rs,toml,html,css --color always -- " cover_cmd := 'cargo llvm-cov --color always --ignore-filename-regex "main\.rs|log\.rs"' last_tag := `git tag --sort=-creatordate | head -1 | tr -d v` From c2de0283fd48ca6f3f96aee8c19499ecee7f136a Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 10:28:47 -0300 Subject: [PATCH 33/44] Update roadmap --- static/graph.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/graph.toml b/static/graph.toml index 23bba0b..ec33fd9 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -908,9 +908,9 @@ text = """ ## Upcoming ## `v0.5.0-alpha` -- [ ] Rich connections +- [ ] Custom kind for connections - [ ] Docs for custom assets and templates -- [ ] Fix anchors containing `/` and `#` considered node IDs +- [x] Fix anchors containing `/` and `#` considered node IDs - [x] Fix `PreFormat` blocks rendering HTML tags
From e0a5eaaf2f8b87fa4633780baba93ce19d34a343 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 10:51:26 -0300 Subject: [PATCH 34/44] Rename Start to Introduction, tweak About page links --- static/graph.toml | 10 +++++----- templates/about.html | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/static/graph.toml b/static/graph.toml index ec33fd9..b961c43 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -1,8 +1,8 @@ #:schema ./graph-schema.json -root_node = "Start" +root_node = "Introduction" -[nodes.Start] +[nodes.Introduction] text = """ ## What is en? @@ -29,11 +29,11 @@ en is in its infancy. Right now, most of the work is focused on making the marku - JSON schema for language server integration - Full-text search -If you like what you see and are curious about en's future, take a look at the |roadmap| for a more comprehensive outlook of what else is to come. +If you like what you see and are curious about en's future, take a look at the |roadmap| for a more comprehensive view of what else is to come. ## Get started -See the |GetStarted| page to learn how to install and use en +See the |Get Started|GetStarted| page to learn how to install and use en. """ [nodes.GetStarted] @@ -900,7 +900,7 @@ en is only possible thanks to a number of projects and people: """ [nodes.RedirectTest] -redirect = "Start" +redirect = "Node" [nodes.Roadmap] text = """ diff --git a/templates/about.html b/templates/about.html index a883140..ce09cf9 100644 --- a/templates/about.html +++ b/templates/about.html @@ -15,10 +15,10 @@

If you'd like to learn more:

{% endif %} From 47f8530487b45ce42fa1de49a699040c882c1cfb Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 12:49:59 -0300 Subject: [PATCH 35/44] Add spelling and TOML schema checks --- .forgejo/workflows/setup-tools.sh | 35 +++++++++++++++++++++++++++---- .justfile | 14 +++++++++++-- Cargo.toml | 9 ++++++++ src/router/handlers/fixed.rs | 4 ++-- static/graph.toml | 24 ++++++++++++--------- static/welcome.toml | 2 ++ 6 files changed, 70 insertions(+), 18 deletions(-) diff --git a/.forgejo/workflows/setup-tools.sh b/.forgejo/workflows/setup-tools.sh index ff6e814..dfcb6f8 100755 --- a/.forgejo/workflows/setup-tools.sh +++ b/.forgejo/workflows/setup-tools.sh @@ -9,12 +9,21 @@ CARGO_LLVM_COV_SHA256SUM="57f491aedf7cdb261538ceb49cbb1ee9d27df7ca205a5e1a009caa CARGO_AUDIT_VERSION="0.22.1" CARGO_AUDIT_TAG="cargo-audit%2Fv$CARGO_AUDIT_VERSION" CARGO_AUDIT_SHA256SUM="1890badd5f15831a9af4b074399fcd21e6f7c0fe42c84e9254cdffc9f813765c" +TAPLO_VERSION="0.10.0" +TAPLO_SHA256SUM="8fe196b894ccf9072f98d4e1013a180306e17d244830b03986ee5e8eabeb6156" +TYPOS_VERSION="1.47.2" +TYPOS_SHA256SUM="7aef58932fc123b4cf4b40d86468e89a3297d80169051d7cfd13a235e05fc426" TRIPLE="x86_64-unknown-linux-gnu" TRIPLE_MUSL="x86_64-unknown-linux-musl" fetch() { - repo="$1"; tag="$2"; filename="$3"; digest="$4"; binary="$5" + repo="$1" + tag="$2" + filename="$3" + digest="$4" + binary="$5" + renamed_binary="${6:-$binary}" [ -d /tmp/tools ] || mkdir -p /tmp/tools @@ -24,9 +33,19 @@ fetch() { printf '%s %s\n' "$digest" "/tmp/$filename" > /tmp/digest sha256sum --check /tmp/digest - tar xf "/tmp/$filename" -C /tmp/tools - find /tmp/tools -type f -executable -name "$binary" \ - -exec mv -v '{}' /usr/local/bin ';' + + if printf '%s' "$filename" | grep -qE '\.tar\.|\.tgz$'; then + tar xf "/tmp/$filename" -C /tmp/tools + elif printf '%s' "$filename" | grep -q '\.gz$'; then + gunzip -c "/tmp/$filename" > "/tmp/tools/$binary" + else + echo "Fatal: can't determine how to unpack $filename" + exit 1 + fi + + find /tmp/tools -type f -name "$binary" \ + -exec mv -v '{}' "/usr/local/bin/$renamed_binary" ';' + chmod +x "/usr/local/bin/$renamed_binary" } fetch casey/just "$JUST_VERSION" \ @@ -40,3 +59,11 @@ fetch taiki-e/cargo-llvm-cov "v$CARGO_LLVM_COV_VERSION" \ fetch rustsec/rustsec "$CARGO_AUDIT_TAG" \ "cargo-audit-$TRIPLE-v$CARGO_AUDIT_VERSION.tgz" \ "$CARGO_AUDIT_SHA256SUM" cargo-audit + +fetch tamasfe/taplo "$TAPLO_VERSION" \ + "taplo-linux-x86_64.gz" \ + "$TAPLO_SHA256SUM" taplo-linux-x86_64 taplo + +fetch crate-ci/typos "v$TYPOS_VERSION" \ + "typos-v$TYPOS_VERSION-$TRIPLE_MUSL.tar.gz" \ + "$TYPOS_SHA256SUM" typos diff --git a/.justfile b/.justfile index 28649d6..9ae185c 100644 --- a/.justfile +++ b/.justfile @@ -51,7 +51,7 @@ alias wc := run-watch-containerized [private] assess-quick: - {{ just_cmd }} lint check test-cover-quick + {{ just_cmd }} lint check test-cover-quick spell [private] assess-run-quick: @@ -347,7 +347,7 @@ verify: exit 1 fi {{ just_cmd }} \ - todos-assess version-assess deny \ + todos-assess version-assess spell schema-lint deny \ format-assess lint-assess check \ test "" cover-assess @@ -381,6 +381,16 @@ alias ta := todos-assess deny: cargo deny check +# Check for spelling mistakes +[group: 'assess'] +spell: + typos + +# Lint the default and builtin graphs against the schema +[group: 'assess'] +schema-lint: + test -z "$(grep -LF '#:schema ./graph-schema.json' static/*.toml)" + taplo lint static/*.toml # BUILD diff --git a/Cargo.toml b/Cargo.toml index 130e36b..a3b9a52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -268,3 +268,12 @@ zero_sized_map_values = "warn" negative_feature_names = "warn" redundant_feature_names = "warn" wildcard_dependencies = "warn" + +[package.metadata.typos.default] +extend-ignore-re = [ + "oficial do Brasil", + "Creative Commons ND", + "Creative Commons BY-ND", + "CC_BY_ND_", + "(?ms)^mod tests \\{.*^\\}", +] diff --git a/src/router/handlers/fixed.rs b/src/router/handlers/fixed.rs index d9bd120..bf905ed 100644 --- a/src/router/handlers/fixed.rs +++ b/src/router/handlers/fixed.rs @@ -216,7 +216,7 @@ impl Asset { /// /// Defaults are found in the `fixed::DEFAULTS` map. /// -/// Returns a `FallbackError` if neither is found or an I/O error ocurred. +/// Returns a `FallbackError` if neither is found or an I/O error occurred. fn fallback(path: &str, graph: &Graph) -> Result { let target = format!("static/public/assets/{path}"); let defaults: HashMap<&str, &str> = TEXTS.iter().copied().collect(); @@ -292,7 +292,7 @@ pub async fn file( } else { String::from( "The requested file exists, but the server lacks \ - permission to access it or another I/O error ocurred.", + permission to access it or another I/O error occurred.", ) }; if log::env_level() >= DEBUG { diff --git a/static/graph.toml b/static/graph.toml index b961c43..efd69d4 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -6,13 +6,13 @@ root_node = "Introduction" text = """ ## What is en? -en is a writing tool. It was designed with complex, conceptually heavy projects, where the relationships between terms matter and possibly have their own attributes. You can use it to write non-linear, connected textual works and have their references to which other mapped out as a |graph| of metadata-rich, interrelated information. This very website is running en. +en is a writing tool. It was designed for complex, conceptually heavy projects, where the relationships between terms matter and possibly have their own attributes. You can use it to write non-linear, connected textual works and have their references to which other mapped out as a |graph| of metadata-rich, interrelated information. This very website is running en. It works by ingesting plain text files written in |TOML|, a file format that focuses on being human-readable but that can also be directly interpreted by computer programs. These files contain your node definitions and allow en to construct a human-readable website that makes your graphs' nodes browsable, searchable and listed in relation to each other or as a shallow tree of nodes. It also serves this graph as raw data for integration with other tools that can further analyze and transform what you have written. ## Motivation -en was created out of the desire to write a web of encyclopedic-style long-form texts documenting a personal worldview. It aims to remove the constraints imposed by trying to mimic the linearity of a typical nonfiction book. +en was created out of the desire to write a book that did not follow a linear progression. But it can be used for note-taking, studying, documentation, encyclopedic content and any other format that benefits from a focus on the connections between pages. It aims to remove the constraints imposed by trying to mimic the linearity of typical nonfiction writing. It's described as a "writing instrument" because it's not so much about the presentation or even the web format. While that's the medium for this particular implementation, you can notice en serves its raw data in both TOML and JSON. It's first and foremost about mapping out and structuring written thoughts. @@ -908,11 +908,22 @@ text = """ ## Upcoming ## `v0.5.0-alpha` -- [ ] Custom kind for connections - [ ] Docs for custom assets and templates +- [ ] Custom kind for connections +- [ ] Hide tree leaves from the top level - [x] Fix anchors containing `/` and `#` considered node IDs - [x] Fix `PreFormat` blocks rendering HTML tags +## `v0.6.0-alpha` +- [ ] Custom header include + +## `v0.7.0-alpha` +- [ ] Frontmatter format +- [ ] Multi-file graphs + +## `v0.8.0-alpha` +- [ ] Full-text search +
## Backlog @@ -943,12 +954,10 @@ text = """ - [ ] By most linked to - [ ] By most linked - Tree - - [ ] Hide tree leaves from the top level - [ ] Branch deeper - Customization - [ ] Custom assets (favicon, CSS) - [x] Drop all hardcoded assets endpoints - - [ ] Custom header include - [x] Custom templates - [ ] user-supplied loading order (e.g. through filenames) - [ ] Themes @@ -974,8 +983,6 @@ text = """ ### I/O formats #### Input -- [ ] Frontmatter format -- [ ] Multi-file graphs - [ ] Multi-graph #### Output @@ -991,9 +998,6 @@ text = """ - [ ] Reduce whitespace - See: |https://keats.github.io/tera/docs/#whitespace-control| -### Server -- [ ] Full-text search - ### Documentation - [ ] Generate `meta.config` docs from JSON schema diff --git a/static/welcome.toml b/static/welcome.toml index 7ff2d33..90341de 100644 --- a/static/welcome.toml +++ b/static/welcome.toml @@ -1,3 +1,5 @@ +#:schema ./graph-schema.json + [nodes.GettingStarted] title = "Getting Started" text = """ From 83d7b7e7aa3c118f47f1bb42cc10e547ca983c6c Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 13:14:08 -0300 Subject: [PATCH 36/44] CI: Allow manually triggering publish workflow --- .forgejo/workflows/publish.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.forgejo/workflows/publish.yaml b/.forgejo/workflows/publish.yaml index fc546f8..6a96939 100644 --- a/.forgejo/workflows/publish.yaml +++ b/.forgejo/workflows/publish.yaml @@ -2,6 +2,14 @@ on: push: tags: - 'v*' + workflow_dispatch: + inputs: + upload: + description: 'Upload built assets to the git.jutty.dev package registry' + type: boolean + required: false + default: true + jobs: publish: runs-on: docker @@ -45,6 +53,7 @@ jobs: run: just shasum - name: Publish x64 glibc binary to git.jutty.dev registry + if: ${{ inputs.upload }} run: | version=$(./target/x86_64-unknown-linux-gnu/release/en --version) api_root=https://git.jutty.dev/api @@ -55,6 +64,7 @@ jobs: --upload-file target/x86_64-unknown-linux-gnu/release/en $url - name: Publish x64 musl binary to git.jutty.dev registry + if: ${{ inputs.upload }} run: | version=$(./target/x86_64-unknown-linux-musl/release/en --version) api_root=https://git.jutty.dev/api From 2a01b9ac4cec6139dc0c83233b1168b555a44c58 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 16:49:50 -0300 Subject: [PATCH 37/44] CI: Add new assessments to verify workflow, improve Git tag check --- .forgejo/workflows/setup-tools.sh | 6 +++++ .forgejo/workflows/verify.yaml | 10 ++++--- .justfile | 43 +++++++++++++++++-------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/.forgejo/workflows/setup-tools.sh b/.forgejo/workflows/setup-tools.sh index dfcb6f8..3c71b7c 100755 --- a/.forgejo/workflows/setup-tools.sh +++ b/.forgejo/workflows/setup-tools.sh @@ -13,6 +13,8 @@ TAPLO_VERSION="0.10.0" TAPLO_SHA256SUM="8fe196b894ccf9072f98d4e1013a180306e17d244830b03986ee5e8eabeb6156" TYPOS_VERSION="1.47.2" TYPOS_SHA256SUM="7aef58932fc123b4cf4b40d86468e89a3297d80169051d7cfd13a235e05fc426" +CARGO_DENY_VERSION="0.19.8" +CARGO_DENY_SHA256SUM="70e769ae3872e34d45132b17040859175e11401dc12dddb0303e0b8c7d088f3f" TRIPLE="x86_64-unknown-linux-gnu" TRIPLE_MUSL="x86_64-unknown-linux-musl" @@ -67,3 +69,7 @@ fetch tamasfe/taplo "$TAPLO_VERSION" \ fetch crate-ci/typos "v$TYPOS_VERSION" \ "typos-v$TYPOS_VERSION-$TRIPLE_MUSL.tar.gz" \ "$TYPOS_SHA256SUM" typos + +fetch EmbarkStudios/cargo-deny "$CARGO_DENY_VERSION" \ + cargo-deny-$CARGO_DENY_VERSION-$TRIPLE_MUSL.tar.gz \ + "$CARGO_DENY_SHA256SUM" cargo-deny diff --git a/.forgejo/workflows/verify.yaml b/.forgejo/workflows/verify.yaml index 2d4e590..c37f8e7 100644 --- a/.forgejo/workflows/verify.yaml +++ b/.forgejo/workflows/verify.yaml @@ -9,6 +9,7 @@ on: - .forgejo/** - Cargo.toml - Cargo.lock + jobs: verify: runs-on: docker @@ -39,9 +40,12 @@ jobs: useradd -m ci && chown -R ci:ci . git config --global --add safe.directory "$PWD" - - name: Build - run: just ci build - + - name: Text matching checks + run: just ci todos-assess version-assess spell + - name: Schema lint + run: just ci schema-lint + - name: Deny + run: just ci deny - name: Format run: just ci format-assess - name: Lint diff --git a/.justfile b/.justfile index 9ae185c..9c7d7d3 100644 --- a/.justfile +++ b/.justfile @@ -51,7 +51,7 @@ alias wc := run-watch-containerized [private] assess-quick: - {{ just_cmd }} lint check test-cover-quick spell + {{ just_cmd }} lint check test-cover-quick spell schema-lint [private] assess-run-quick: @@ -219,8 +219,8 @@ mutate-single *cargo_test_args: # Tag HEAD with version from Cargo.toml [script, group: 'assess'] tag commit="HEAD": update - if [ "{{ last_tag }}" = "{{ manifest_version }}" ]; then - echo "Last tag {{ last_tag }} and manifest ({{ manifest_version }}) already match" + if [ "{{ last_local_tag }}" = "{{ manifest_version }}" ]; then + echo "Last tag {{ last_local_tag }} and manifest ({{ manifest_version }}) already match" exit elif [ "{{ manifest_version }}" != "{{ lockfile_version }}" ]; then echo "Manifest and lockfile versions don't match: update failed?" @@ -231,15 +231,15 @@ tag commit="HEAD": update {{ just_cmd }} version-assess # Verify and push -[group: 'develop'] -push: verify +[group: 'develop', env("JUST", "1")] +push: verify && (version-assess "true") git push git push --tags alias p := push # Push without verifying -[group: 'develop'] +[group: 'develop', env("JUST", "1")] push-unsafe: git push --no-verify git push --tags --no-verify @@ -355,16 +355,21 @@ alias v := verify # Check tag-manifest consistency [script, group: 'assess'] -version-assess: update - if - [ "{{ last_tag }}" != "{{ lockfile_version }}" ] \ - || [ "{{ last_tag }}" != "{{ lockfile_version }}" ] - then - printf 'Last tag: %s\nManifest: %s\nLockfile: %s\n' \ - "{{ last_tag }}" \ - "{{ manifest_version }}" \ - "{{ lockfile_version }}" - exit 1 +[arg("remote", long="remote", short="r", value="true")] +version-assess remote="false": update + last_remote_tag=$( + git ls-remote --tags --sort=-creatordate origin | + head -n 1 | tr -d v | cut -d / -f 3 + ) + printf 'Local: %s\nRemote: %s\nManifest: %s\nLockfile: %s\n' \ + "{{ last_local_tag }}" \ + "$last_remote_tag" \ + "{{ manifest_version }}" \ + "{{ lockfile_version }}" + test "{{ last_local_tag }}" = "{{ lockfile_version }}" + test "{{ last_local_tag }}" = "{{ manifest_version }}" + if {{ if remote == "true" { "true" } else { "false" } }}; then + test "{{ last_local_tag }}" = "$last_remote_tag" fi alias va := version-assess @@ -379,7 +384,7 @@ alias ta := todos-assess # Check for security advisories, unexpected licenses, allowed registries [group: 'assess'] deny: - cargo deny check + cargo-deny check # Check for spelling mistakes [group: 'assess'] @@ -463,7 +468,7 @@ choose: alias ch := choose -[script, private] +[script, private, env("CARGO_HOME", "$HOME/.cargo")] ci recipe: su ci -c "just {{ recipe }}" @@ -481,7 +486,7 @@ just_cmd_no_ts := 'just --explain --command-color green' watch_cmd := "watchexec -qc -r -e rs,toml,html,css --color always -- " cover_cmd := 'cargo llvm-cov --color always --ignore-filename-regex "main\.rs|log\.rs"' -last_tag := `git tag --sort=-creatordate | head -1 | tr -d v` +last_local_tag := `git tag --sort=-creatordate | head -n 1 | tr -d v` manifest_version := `grep "^version" Cargo.toml | cut -d \" -f 2` lockfile_version := ``` grep -A 1 'name = "en"' Cargo.lock \ diff --git a/Cargo.lock b/Cargo.lock index daa0607..d0133a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -238,7 +238,7 @@ dependencies = [ [[package]] name = "en" -version = "0.4.1-alpha" +version = "0.4.0-alpha" dependencies = [ "axum", "serde", diff --git a/Cargo.toml b/Cargo.toml index a3b9a52..5c79e7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "en" -version = "0.4.1-alpha" +version = "0.4.0-alpha" description = "A non-linear writing instrument." license = "AGPL-3.0-only" From 297030696ef98a3f79aecbe772778b355476a18f Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 17:39:57 -0300 Subject: [PATCH 38/44] Merge planned features overview in README with the Intro's --- README.md | 11 ++--------- static/graph.toml | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4248c56..960f996 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,6 @@ See the [Documentation](https://en.jutty.dev/node/Documentation) page for instru ## Roadmap -On a high-level, here are some things that en intends to achieve at some point: +For a high-level view of what's in the future for en, see the [What's ahead section](https://en.jutty.dev/node/Introduction/#What's) of the docs Introduction. -1. Separate 'en' the server from 'en' the source-to-source translator. This would allow using en's markup syntax as a standalone compile-to-HTML language, effectively creating an "en cli" that should also have options to make it more practical to manipulate a graph, such as adding new nodes or querying your graph -3. Multifile graphs, with _optional_ TOML frontmatter -2. Make en more fitting to the 'note taking' use case -3. Multigraph, with the server being capable to let the user choose which graph to render and with inter-graph connections -4. Different rendering modes such as to a static website, to PDF or EPUB (with paper-friendly metadata) -5. Stateful and stateless online graph editing with 'export to TOML' - -For a more detailed outline of what's planned for the future of en, along with what's already been completed, see the [roadmap](https://en.jutty.dev/node/Roadmap). +For a more detailed outline of what's planned, along with what's already been completed, see the [roadmap](https://en.jutty.dev/node/Roadmap). diff --git a/static/graph.toml b/static/graph.toml index efd69d4..bc51702 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -23,11 +23,13 @@ Because your en graph is defined in simple plain-text files, you can add new pag en is in its infancy. Right now, most of the work is focused on making the markup syntax more robust. Some interesting features planned include: - Multi-file graphs, including single-file node definitions with TOML frontmatter -- Richer node connection metrics and sorting -- Builtin and custom connection kinds with special rendering styles -- More render formats: static website, single page and PDF/EPUB formats +- Richer node connection metadata, with builtin connection kinds and special rendering styles +- More node metrics, sorting options and full-text search +- New render formats: static website, single page and PDF/EPUB formats with paper-friendly metadata - JSON schema for language server integration -- Full-text search +- Separating the server from the source-to-source translator, allowing en's markup syntax to be used as a standalone compile-to-HTML language +- Adding CLI options to make it more practical to manipulate a graph, such as adding new nodes or querying your graphagarn +- Hypergraphs, enabling cross-graph references and letting the user choose which graph to render If you like what you see and are curious about en's future, take a look at the |roadmap| for a more comprehensive view of what else is to come. @@ -179,7 +181,7 @@ en take as its input one or more graph files containing your node definitions. I - A |TOML| representation of the graph that can be used as a basis to generate other, adapted graphs - A JSON representation of the graph that can be further analyzed and interpreted with third-party tools -The output formats are not simply a translation of the input, but enrich them. Among other things, they transpile en's |markup syntax|Syntax into HTML, add metrics about how nodes are connected and flag which missing nodes are most sought after by dangling connections. +The output formats are not simply a translation of the input, but enrich them. Among other things, they translate en's |markup syntax|Syntax into HTML, add metrics about how nodes are connected and flag which missing nodes are most sought after by dangling connections. """ [nodes.SourceBuild] @@ -907,26 +909,33 @@ text = """ ## Upcoming -## `v0.5.0-alpha` +### v0.5.0-alpha - [ ] Docs for custom assets and templates - [ ] Custom kind for connections - [ ] Hide tree leaves from the top level - [x] Fix anchors containing `/` and `#` considered node IDs - [x] Fix `PreFormat` blocks rendering HTML tags -## `v0.6.0-alpha` +### v0.6.0-alpha - [ ] Custom header include -## `v0.7.0-alpha` +### v0.7.0-alpha - [ ] Frontmatter format - [ ] Multi-file graphs -## `v0.8.0-alpha` +### v0.8.0-alpha - [ ] Full-text search -
+
+ +_See |Changelog|Roadmap#Changelog| for previously released versions._ + +
+
## Backlog +These changes are planned, but have not been assigned to an upcoming release yet. + ### Syntax - [ ] Improve nested formatting - [ ] Invert where redirects are set @@ -1064,6 +1073,15 @@ text = """ - [x] Further centralize state
+ +
+ +## Changelog + +### |v0.4.0-alpha|https://codeberg.org/jutty/en/releases/tag/v0.4.0-alpha| + +- Embed assets and welcome graph into the binary +- Source custom templates and assets from `./templates` and `./static/public` """ [meta.config] From 4d7ae2e7290ce1d7e1e80e9bde9e248776e31327 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 17:40:05 -0300 Subject: [PATCH 39/44] Tweak paragraph and header spacing --- static/public/assets/style.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static/public/assets/style.css b/static/public/assets/style.css index 8afbacd..b92a157 100644 --- a/static/public/assets/style.css +++ b/static/public/assets/style.css @@ -34,6 +34,7 @@ p:not(.quote-citation), section li { section p { line-height: 2; + margin: 4px 0 16px; } pre { @@ -178,7 +179,7 @@ main h2 { h1, h2, h3, h4, h5, h6 { font-weight: 1; - margin: 10px 0; + margin: 10px 0 5px; overflow-wrap: break-word; } From 26ba5c90e642eb932e673bb6e8e7be024c0ecc0f Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 4 Jun 2026 22:26:08 -0300 Subject: [PATCH 40/44] Update README for v0.5 node structure --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 960f996..2416d37 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ You can learn more and see what en looks like by visiting the [homepage](https:/ ## Install and run -See the [Documentation](https://en.jutty.dev/node/Documentation) page for instructions and how to install and start using en. +See the [Get Started](https://en.jutty.dev/node/GetStarted) page for instructions and how to install and start using en. ## Roadmap -For a high-level view of what's in the future for en, see the [What's ahead section](https://en.jutty.dev/node/Introduction/#What's) of the docs Introduction. +For a high-level view of what's in the future for en, see the [What's ahead section](https://en.jutty.dev/node/Introduction#What's) of the docs Introduction. For a more detailed outline of what's planned, along with what's already been completed, see the [roadmap](https://en.jutty.dev/node/Roadmap). From a38d93ba2ac0b3eb4e0c2d10be770493550f58fa Mon Sep 17 00:00:00 2001 From: jutty Date: Fri, 5 Jun 2026 21:31:43 -0300 Subject: [PATCH 41/44] schema: Move node schema to $defs --- static/graph-schema.json | 56 ++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/static/graph-schema.json b/static/graph-schema.json index bbf6cc3..95c177a 100644 --- a/static/graph-schema.json +++ b/static/graph-schema.json @@ -6,7 +6,33 @@ "type": "object", "$defs": { "node": { - + "type": "object", + "title": "Node", + "description": "A node object.", + "example": "[nodes.Earth]\ntext = \"Earth is a planet of the solar system.\"", + "default": null, + "properties": { + "text": { + "type": "string", + "description": "The text content of this node." + }, + "title": { + "type": "string", + "description": "The node display title, useful to make it distinct from the ID.", + "default": "The node's ID." + }, + "listed": { + "type": "boolean", + "description": "Whether this node is shown in listing pages.", + "default": true + }, + "redirect": { + "type": "string", + "description": "A node ID to where any requests for this node will be redirected.", + "default": null + } + }, + "additionalProperties": false } }, "properties": { @@ -23,33 +49,7 @@ "default": null, "type": "object", "additionalProperties": { - "type": "object", - "title": "Node", - "description": "A node object.", - "example": "[nodes.Earth]\ntext = \"Earth is a planet of the solar system.\"", - "default": null, - "properties": { - "text": { - "type": "string", - "description": "The text content of this node." - }, - "title": { - "type": "string", - "description": "The node display title, useful to make it distinct from the ID.", - "default": "The node's ID." - }, - "listed": { - "type": "boolean", - "description": "Whether this node is shown in listing pages.", - "default": true - }, - "redirect": { - "type": "string", - "description": "A node ID to where any requests for this node will be redirected.", - "default": null - } - }, - "additionalProperties": false + "$ref": "#/$defs/node" }, "propertyNames": { "pattern": "^[^-][^!@#$%^&*;:/~| \\]\\[()\\\\]*$" From 0987269307d59a95c57803e5f2ae2607686edea7 Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 7 Jun 2026 04:00:36 -0300 Subject: [PATCH 42/44] Add flake.nix --- .gitignore | 1 + Cargo.lock | 8 +++--- flake.lock | 26 ++++++++++++++++++ flake.nix | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index ea8c4bf..d787b70 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/result diff --git a/Cargo.lock b/Cargo.lock index d0133a5..06b5d60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,9 +86,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" [[package]] name = "block-buffer" @@ -469,9 +469,9 @@ dependencies = [ [[package]] name = "ignore" -version = "0.4.25" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a" +checksum = "b915661dd01db3f05050265b2477bcc6527b3792388e2749b41623cc592be67d" dependencies = [ "crossbeam-deque", "globset", diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8f095cd --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1780453794, + "narHash": "sha256-bXMRa9VTsHSPXL4Cw8R6JJLQeY3Y/IP4+YJCYVmQ7FY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6b316287bae2ee04c9b93c8c858d930fd07d7338", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-26.05", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bfac211 --- /dev/null +++ b/flake.nix @@ -0,0 +1,80 @@ +{ + description = "A non-linear writing instrument."; + + inputs.nixpkgs.url = "nixpkgs/nixos-26.05"; + + outputs = { nixpkgs, self }: let + name = "en"; + version = "0.4.0"; + + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + }); + + in { + packages = forAllSystems (system: let + pkgs = nixpkgsFor.${system}; + in { + default = pkgs.rustPlatform.buildRustPackage { + inherit name version; + src = ./.; + + cargoHash = + "sha256-" + + "em229cShq/IShRnxlp5mgcIu7pIOf0LflV8Pw0lLUEY="; + }; + }); + + apps = forAllSystems (system: { + default = { + type = "app"; + program = + "${self.packages.${system}.default}/bin/en"; + }; + }); + + devShells = forAllSystems (system: + let pkgs = nixpkgsFor.${system}; in { + default = pkgs.mkShell { + buildInputs = with pkgs; [ + rustup + just + watchexec + cargo-deny + cargo-llvm-cov + cargo-mutants + go-tools + typos + taplo + ]; + }; + } + ); + + + nixosModules.bot = { config, lib, system, ... }: { + options.within.services.en.enable = + lib.mkEnableOption "enable en server"; + + config = lib.mkIf config.within.services.en.enable { + systemd.services.en = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Restart = "always"; + ExecStart = + "${self.packages."${system}".default}/bin/en"; + }; + }; + }; + }; + + + }; +} From 1aef9d6ee6a778fdcff142799ee70156e4880dbc Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 7 Jun 2026 05:19:25 -0300 Subject: [PATCH 43/44] Draft customization docs --- static/graph.toml | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/static/graph.toml b/static/graph.toml index bc51702..df35c11 100644 --- a/static/graph.toml +++ b/static/graph.toml @@ -842,6 +842,64 @@ en must differentiate node anchors from outgoing URLs: It does this by looking at the destination and checking if it contains a `/` or `:`. That's one more reason to avoid these characters in your node IDs. """ +[nodes.Customization] +text = """ +You can customize several aspects of en by overriding its default templates, styles and other assets. + +## The `public` directory + +The `static/public` directory is searched by en in the current working directory and can also be |passed as a command line option|CLI. All files placed inside this directory will be served by the en server as static files. You can create directories and organize files as you see fit, and then reference them through custom templates and includes. + +If you place a file in a default path, it will override the default. Namely: + +- `static/public/assets/favicon.svg`: Website icon as seen on tabs and other UI elements +- `static/public/assets/style.css`: Main CSS stylesheet +- `static/public/assets/fonts/fonts.css`: Fonts CSS index mapping the default families `sans`, `serifed`, `mono`, `prose` and `title`. The `prose` family is used for paragraphs such as in the node text content, while the `sans` family is used for UI elements such as the navigation bar and footer. + +The en server supports a variety of file types including plain text; data formats such as CSV, TOML and JSON; various font and image formats; and document formats such as PDF and EPUB. If you want to serve a file with a mimetype that is not included among the |builtin ones|https://codeberg.org/jutty/en/src/branch/main/src/router/handlers/mime.rs|, you can use the `mimes` |configuration option|Configuration#mimes|. If you don't, the file will be served with mimetype `application/octet-stream`, which may or may not work depending on what you are actually serving and how it's being consumed. + +## Styles + +You can override the default CSS and fonts using custom CSS files. + +To completely override the default style, you can place your replacement at the default path as explained in the previous section. + +If you just want to add small customizations, this can be better accomplished by adding a CSS file as part of a custom headers include, as explained in the next section. + +## Templates + +en uses the Tera|https://keats.github.io/tera templating engine, which provides several features for creating your own templates. + +When starting up, en will look for a `templates` directory in the current working directory. For each template, it looks up the corresponding filename inside this directory. If it can't find one, it will fallback to a default template. + +For a list of templates along with their names, see the |templates directory|https://codeberg.org/jutty/en/src/branch/main/templates| in the source code repository. + +See the |Tera documentation|https://keats.github.io/tera/docs for a more extensive description of the available features for writing templates. + +### Includes + +Overriding an entire template can be very verbose, considering the default templates attempt to handle various edge cases. + +To make it easier to override the most common use cases, the following templates are consumed as "includes" in specific parts of the main templates if placed inside the `templates` directory with the suffix `.include.html`: + +- `header`: Included at the end of the default templates' base header +- `post-body`: Included after the body in the default base template +- `favicon`: Replaces the default favicon code +- `styles`: Replaces the default CSS links +- `footer`: Replaces the footer +- `navigation`: Replaces the navigation bar +- `index-header`: Replaces the block showing the title and subtitle of the website in the index page +- `index-list`: Replaces the block showing the list of nodes in the index page + +For example, to override the block in the header of all pages that globally sets the CSS stylesheets, you can drop a file at `templates/styles.include.html` containing something like: + +` + + +` + +""" + [nodes.Graph] text = """ A graph is a data structure composed of connected (and disconnected) nodes. From f8708f2500e5154c1ea4adb5214ae6e95056b314 Mon Sep 17 00:00:00 2001 From: jutty Date: Mon, 8 Jun 2026 00:52:48 -0300 Subject: [PATCH 44/44] Add several new lints from latest Clippy versions --- Cargo.toml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 5c79e7d..833205b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ cast_sign_loss = "warn" checked_conversions = "warn" clear_with_drain = "warn" cloned_instead_of_copied = "warn" +cmp_owned = "warn" coerce_container_to_any = "warn" collapsible_else_if = "allow" collapsible_if = "allow" @@ -70,6 +71,7 @@ doc_link_code = "warn" doc_link_with_quotes = "warn" doc_markdown = "warn" doc_paragraphs_missing_punctuation = "warn" +double_must_use = "warn" duration_suboptimal_units = "warn" empty_drop = "warn" empty_enum_variants_with_brackets = "warn" @@ -80,6 +82,7 @@ error_impl_error = "warn" exit = "warn" expect_used = "warn" expl_impl_clone_on_copy = "warn" +explicit_counter_loop = "warn" explicit_deref_methods = "warn" explicit_into_iter_loop = "warn" explicit_iter_loop = "warn" @@ -107,6 +110,7 @@ index_refutable_slice = "warn" indexing_slicing = "warn" inefficient_to_string = "warn" infinite_loop = "warn" +int_plus_one = "warn" integer_division = "warn" integer_division_remainder_used = "warn" into_iter_without_iter = "warn" @@ -114,6 +118,7 @@ invalid_upcast_comparisons = "warn" ip_constant = "warn" iter_filter_is_ok = "warn" iter_filter_is_some = "warn" +iter_kv_map = "warn" iter_not_returning_iterator = "warn" iter_on_empty_collections = "warn" iter_on_single_items = "warn" @@ -129,14 +134,19 @@ literal_string_with_formatting_args = "warn" lossy_float_literal = "warn" macro_use_imports = "warn" manual_assert = "warn" +manual_checked_ops = "warn" manual_ilog2 = "warn" manual_instant_elapsed = "warn" +manual_is_multiple_of = "warn" manual_is_power_of_two = "warn" manual_is_variant_and = "warn" manual_let_else = "warn" manual_midpoint = "warn" manual_non_exhaustive = "allow" +manual_option_zip = "warn" +manual_pop_if = "warn" manual_string_new = "warn" +manual_take = "warn" many_single_char_names = "warn" map_err_ignore = "warn" map_with_unused_argument_over_ranges = "warn" @@ -179,15 +189,19 @@ option_option = "warn" panic_in_result_fn = "warn" path_buf_push_overwrite = "warn" pathbuf_init_then_push = "warn" +possible_missing_else = "warn" pub_underscore_fields = "warn" pub_without_shorthand = "warn" +question_mark = "warn" range_minus_one = "warn" range_plus_one = "warn" rc_buffer = "warn" rc_mutex = "warn" read_zero_byte_vec = "warn" redundant_clone = "warn" +redundant_closure = "warn" redundant_closure_for_method_calls = "warn" +redundant_iter_cloned = "warn" redundant_pub_crate = "warn" redundant_test_prefix = "warn" redundant_type_annotations = "warn" @@ -195,6 +209,7 @@ ref_binding_to_reference = "warn" ref_option = "warn" ref_option_ref = "warn" renamed_function_params = "warn" +replace_box = "warn" rest_pat_in_fully_bound_structs = "warn" return_and_then = "warn" return_self_not_must_use = "warn" @@ -235,12 +250,17 @@ unchecked_time_subtraction = "warn" unicode_not_nfc = "warn" uninlined_format_args = "warn" unnecessary_box_returns = "warn" +unnecessary_cast = "warn" unnecessary_debug_formatting = "warn" +unnecessary_fold = "warn" unnecessary_join = "warn" unnecessary_literal_bound = "warn" +unnecessary_option_map_or_else = "warn" +unnecessary_result_map_or_else = "warn" unnecessary_self_imports = "warn" unnecessary_semicolon = "warn" unnecessary_struct_initialization = "warn" +unnecessary_trailing_comma = "warn" unnecessary_wraps = "warn" unneeded_field_pattern = "warn" unnested_or_patterns = "warn" @@ -257,6 +277,8 @@ unwrap_in_result = "warn" unwrap_used = "warn" used_underscore_binding = "warn" used_underscore_items = "warn" +useless_concat = "warn" +useless_conversion = "warn" useless_let_if_seq = "warn" verbose_file_reads = "warn" volatile_composites = "warn"