Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
111849d92a | ||
|
|
235384fb85 | ||
|
|
a9b59b361e | ||
|
|
c4501a17f2 | ||
|
|
5f00572e24 |
No files matched your search
@@ -1,2 +0,0 @@
|
||||
* text=auto
|
||||
*.sh text eol=lf
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
name: 功能、缺陷或迁移
|
||||
about: 记录唯一负责仓库、可复现候选与验收
|
||||
---
|
||||
|
||||
## 问题与所有权
|
||||
|
||||
- 责任组件(全局 ID / 仓库):
|
||||
- 类型:bug | missing capability | contract change | migration
|
||||
- 影响消费者(ID / 关联工单):
|
||||
- 权威合同链接:
|
||||
|
||||
## 可复现的候选组合
|
||||
|
||||
- 根 / 领域 / 组件 SHA:
|
||||
- CLI、Worker、Stdlib、依赖制品 SHA-256 与平台:
|
||||
- 环境与工具链:
|
||||
- 最小 fixture / 命令 / 实际结果:
|
||||
- 预期结果:
|
||||
|
||||
## 修复范围
|
||||
|
||||
- 必须:
|
||||
- 禁止:兼容旧协议、复制实现、无关重构、扩大权限等
|
||||
- 上游阻塞:<工单链接或无>
|
||||
|
||||
## 验收
|
||||
|
||||
- 正例:
|
||||
- 负例 / 授权与安全边界:
|
||||
- 回归 / 性能条件:
|
||||
- 组件 CI:
|
||||
- 领域 / 消费者组合测试:
|
||||
- 修复提交与制品证据:
|
||||
@@ -1,25 +0,0 @@
|
||||
## 工单与责任仓库
|
||||
|
||||
- 责任工单:
|
||||
- 唯一责任仓库与组件 ID:
|
||||
- 本次变更是否涉及 domain、gitlink、`planned → active` 或公共合同:<是/否,说明>
|
||||
|
||||
## 组合与证据
|
||||
|
||||
- 组件提交(C2)/ 领域组合(B2)/ 根组合(A2):
|
||||
- C1/C2/C3 CI 链接:
|
||||
- 可复现命令、平台、依赖制品摘要:
|
||||
- 本次未运行 / UNVERIFIED 的项:
|
||||
|
||||
## 分层与边界检查
|
||||
|
||||
- [ ] 变更落在唯一责任仓库,聚合仓未引入生产实现
|
||||
- [ ] 未创建占位 gitlink 或伪造 active `entry`;planned 不计入验收
|
||||
- [ ] 公共合同变更与实际消费者配对候选,未引入旧协议 fallback
|
||||
- [ ] 主仓库只更新精确 gitlink、治理文件与集成脚本,未借机重构无关组件
|
||||
- [ ] 未在根或聚合脚本中加入 workaround、复制协议或绕开权限
|
||||
|
||||
## 发行与回滚
|
||||
|
||||
- 公共协议 / 制品影响:
|
||||
- 旧基线或回滚方式(恢复上一组已接受 gitlink):
|
||||
Executable → Regular
+1
-9
@@ -1,9 +1 @@
|
||||
.env
|
||||
.env.*
|
||||
/.migration-work/
|
||||
/.integration-work/
|
||||
/__pycache__/
|
||||
**/__pycache__/
|
||||
|
||||
# Local build/cache/scratch (DSH workspace tooling)
|
||||
/.build/
|
||||
/target
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
[submodule "cli"]
|
||||
path = cli
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-cli.git
|
||||
[submodule "tests/conformance"]
|
||||
path = tests/conformance
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-extension-conformance.git
|
||||
[submodule "tools/view"]
|
||||
path = tools/view
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-view.git
|
||||
[submodule "tools/knowledge"]
|
||||
path = tools/knowledge
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-knowledge.git
|
||||
[submodule "tools/prove"]
|
||||
path = tools/prove
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-prove.git
|
||||
[submodule "tools/lint"]
|
||||
path = tools/lint
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-lint.git
|
||||
[submodule "extensions/ai"]
|
||||
path = extensions/ai
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-ai.git
|
||||
[submodule "extensions/archive"]
|
||||
path = extensions/archive
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-archive.git
|
||||
[submodule "extensions/browser"]
|
||||
path = extensions/browser
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-browser.git
|
||||
[submodule "extensions/cache"]
|
||||
path = extensions/cache
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-cache.git
|
||||
[submodule "extensions/crypto"]
|
||||
path = extensions/crypto
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-crypto.git
|
||||
[submodule "extensions/database"]
|
||||
path = extensions/database
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-database.git
|
||||
[submodule "extensions/datetime"]
|
||||
path = extensions/datetime
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-datetime.git
|
||||
[submodule "extensions/document"]
|
||||
path = extensions/document
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-document.git
|
||||
[submodule "extensions/engineering"]
|
||||
path = extensions/engineering
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-engineering.git
|
||||
[submodule "extensions/http"]
|
||||
path = extensions/http
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-http.git
|
||||
[submodule "extensions/linalg"]
|
||||
path = extensions/linalg
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-linalg.git
|
||||
[submodule "extensions/math"]
|
||||
path = extensions/math
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-math.git
|
||||
[submodule "extensions/mcp"]
|
||||
path = extensions/mcp
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-mcp.git
|
||||
[submodule "extensions/quantum"]
|
||||
path = extensions/quantum
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-quantum.git
|
||||
[submodule "extensions/regex"]
|
||||
path = extensions/regex
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-regex.git
|
||||
[submodule "extensions/security"]
|
||||
path = extensions/security
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-security.git
|
||||
[submodule "extensions/storage"]
|
||||
path = extensions/storage
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-storage.git
|
||||
[submodule "extensions/web"]
|
||||
path = extensions/web
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-web.git
|
||||
[submodule "extensions/websocket"]
|
||||
path = extensions/websocket
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-websocket.git
|
||||
[submodule "stdlib/collections"]
|
||||
path = stdlib/collections
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-collections.git
|
||||
[submodule "stdlib/core"]
|
||||
path = stdlib/core
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-core.git
|
||||
[submodule "stdlib/data"]
|
||||
path = stdlib/data
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-data.git
|
||||
[submodule "stdlib/encoding"]
|
||||
path = stdlib/encoding
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-encoding.git
|
||||
[submodule "stdlib/fs"]
|
||||
path = stdlib/fs
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-fs.git
|
||||
[submodule "stdlib/io"]
|
||||
path = stdlib/io
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-io.git
|
||||
[submodule "stdlib/net"]
|
||||
path = stdlib/net
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-net.git
|
||||
[submodule "stdlib/system"]
|
||||
path = stdlib/system
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-system.git
|
||||
[submodule "stdlib/text"]
|
||||
path = stdlib/text
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-text.git
|
||||
@@ -1,40 +0,0 @@
|
||||
when:
|
||||
event: [push, pull_request, manual]
|
||||
|
||||
steps:
|
||||
layout:
|
||||
image: rust:1.100-bookworm
|
||||
commands:
|
||||
- apt-get update && apt-get install -y --no-install-recommends ca-certificates git python3
|
||||
- python3 scripts/check-layout.py
|
||||
- python3 -m unittest discover -s tests/integration
|
||||
- git submodule update --init
|
||||
- |
|
||||
set -eu
|
||||
domains="$(python3 scripts/check-layout.py --domain-paths)"
|
||||
for domain in $domains; do
|
||||
git -C "$domain" submodule update --init
|
||||
done
|
||||
- python3 scripts/check-layout.py --checkouts
|
||||
|
||||
candidate:
|
||||
# Match the Linux/glibc environment already used by View for the RC.4 artifact.
|
||||
image: mcr.microsoft.com/playwright:v1.49.0-noble
|
||||
depends_on: [layout]
|
||||
commands:
|
||||
- |
|
||||
set -eu
|
||||
for attempt in 1 2 3; do
|
||||
if apt-get -o Acquire::By-Hash=force -o Acquire::Retries=3 update --error-on=any; then
|
||||
break
|
||||
fi
|
||||
if [ "$attempt" -eq 3 ]; then
|
||||
exit 1
|
||||
fi
|
||||
sleep 15
|
||||
done
|
||||
apt-get -o Acquire::Retries=3 install -y --no-install-recommends ca-certificates curl git python3 python3-jsonschema build-essential
|
||||
curl -fsSL --retry 3 https://sh.rustup.rs -o /tmp/marqdo-rustup.sh
|
||||
sh /tmp/marqdo-rustup.sh -y --profile minimal --default-toolchain 1.100.0 --no-modify-path
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
bash scripts/integration.sh
|
||||
@@ -1,10 +0,0 @@
|
||||
# Marqdo 维护指引
|
||||
|
||||
1. 从 [各仓库任务](docs/REPOSITORY-TASKS.md)、[组件目录](components.toml) 与 [架构边界](docs/ARCHITECTURE.md) 确定**唯一**责任仓库:功能缺陷在功能仓库,领域合同/组合在领域聚合仓库,gitlink、跨领域集成、发行组合与治理在主仓库。主仓库和聚合仓库不实现子组件业务。
|
||||
2. 治理树最多两级:根 → 领域聚合(`kind = "domain"`)→ 功能组件。每个组件只有一个父级,全局 ID 与权威远端唯一,领域聚合仓库只做治理、合同、示例和组合验收。已发布的 `planned` 仓库可以挂载真实 gitlink。激活时登记实际 `entry`,只有通过验收的 active 组件计入完成率。
|
||||
3. 找到或建立责任仓库的工单,按 `.gitea/ISSUE_TEMPLATE/change.md` 记录目标、当前提交、最小复现、公共契约、影响消费者和验收命令。跨仓库阻塞在上游开关联工单,并在消费者记录回归条件。不要按错误最终显示的仓库定责,找第一个违反公开合同的所有者。
|
||||
4. 在责任仓库独立修改、构建和测试。需要调整公共语义时,在 CLI 提交 ADR;调整 Web 作者面语义时,只在 `marqdo-ext-web` 的 [WEB-DESIGN 合同](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md) 走 ADR,并与实际消费者(Design/Preview)同候选验证;不得并列维护第二份现行规范或旧协议 fallback。
|
||||
5. 逐层晋升:功能提交 C2 通过组件 CI → 领域 PR 更新 gitlink 至 C2 并通过领域 CI(B2)→ 主仓库 PR 更新领域 gitlink 至 B2 并通过根递归校验与受影响组合验收(A2)。先推送子仓库提交,再在主仓库提交精确 gitlink;区分组件 CI、公共契约 CI 和生态 CI 证据。以 [开发流程](docs/DEVELOPMENT.md) 为准。
|
||||
6. 新接入组件先核对公开 API、直接依赖、独立入口和实际测试。空仓在 [迁移台账](docs/MIGRATION.md) 中保持 `planned`;Web 领域的 Design/Preview 子组件记录在 `marqdo-ext-web` 自己的 `components.toml`,根目录不登记其后代路径。
|
||||
7. 记录 FAIL 和 UNVERIFIED 的具体环境、命令和日志。只有实际通过且匹配候选 SHA 的证据才可用于集成与发行;模拟、mock 或原型测试不能冒充生产验收。
|
||||
8. Web 边界硬约束:不新增 CLI 核心语法或 Web 专属关键字;不复制 Markdown/语言解析器;默认不允许 HTML 注入、业务 JS 或真实网络/数据库/认证;预览是有限确定性解释,生产实现由成熟框架在目标应用仓库承担。
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "marqdo"
|
||||
version = "0.1.0"
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "marqdo"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
[[bin]]
|
||||
name = "marqdo"
|
||||
path = "src/marqdo.rs"
|
||||
@@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -1,133 +0,0 @@
|
||||
# Marqdo
|
||||
|
||||
**Marqdo 是一门以 Markdown 为源文档的编程语言。** 用 `.mq.md` 可以把业务规则、公式、解释和可执行步骤写在同一份文档中。读者用 Markdown 阅读器查看正文,开发者用 Marqdo 检查、运行和验证其中的程序。这个仓库维护生态组件的集成、验收和发行入口。
|
||||
|
||||
生态治理采用有限分层:主仓库固定领域聚合仓库,领域聚合仓库固定本领域功能仓库,最多两级 Gitlink。主仓库和聚合仓库只做治理、组合与验收,不实现子组件业务;Web 领域把设计文档直接作为原型与工程交付的源材料,详见 [架构边界](docs/ARCHITECTURE.md)。
|
||||
|
||||
## 为什么开发 Marqdo
|
||||
|
||||
规则通常写在说明文档里,实现放在脚本里,结果再写进报告。三份内容分开维护后,读者很难确认某个结果用了哪条规则,也很难重新验证。Marqdo 让解释和计算随同一份源文档修改、评审和运行。它适合写带示例的算法说明、可重跑的分析流程,以及需要交代验证过程的知识文档。
|
||||
|
||||
## 主要特性
|
||||
|
||||
- **Markdown 原生**。文档保留 CommonMark/GFM 的结构,并支持公式。在 `.mq.md` 中,以 `@exec` 标明可执行区,以 `@knowledge` 标明说明与知识区。正文可以直接阅读。
|
||||
- **先检查,再运行**。`marqdo check` 静态检查语法与调用,`--refs` 检查文档引用。Analysis 提供结构化分析结果,供编辑器和独立工具使用。
|
||||
- **可观察的运行**。Rust 解释器显式运行文档代码,Observation 记录执行事件与结果。文件、网络、进程等外部操作受运行模式与能力授权约束。
|
||||
- **可组合的生态**。基础发行包含标准库。程序可以通过锁文件固定包与领域扩展的来源和摘要。阅读、知识索引、证明和静态诊断由独立工具提供。
|
||||
|
||||
## 快速开始
|
||||
|
||||
从 [CLI 发行页](https://git.cflmy.cn/cflmy/marqdo-cli/releases) 下载适合平台的发行包。把解包目录加入 `PATH`,保持 CLI、Worker 和旁置 `stdlib/` 的目录结构。将下面的内容保存为 `hello.mq.md`。
|
||||
|
||||
````markdown
|
||||
# 问候示例
|
||||
|
||||
这一节说明程序的用途。下方函数由 CLI 执行。
|
||||
|
||||
## @exec main
|
||||
|
||||
`params()`
|
||||
|
||||
`打印("你好,Marqdo")`
|
||||
````
|
||||
|
||||
```sh
|
||||
marqdo check hello.mq.md
|
||||
marqdo run hello.mq.md
|
||||
```
|
||||
|
||||
```text
|
||||
你好,Marqdo
|
||||
```
|
||||
|
||||
[CLI 使用指南](https://git.cflmy.cn/cflmy/marqdo-cli) · [语言规范](https://git.cflmy.cn/cflmy/marqdo-cli/src/branch/master/spec/mapping.md)
|
||||
|
||||
## 仓库与职责
|
||||
|
||||
### 已接入的核心和工具
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo](https://git.cflmy.cn/cflmy/marqdo) | 生态主仓库,维护仓库索引、固定提交组合、跨仓库验收与发行 |
|
||||
| [marqdo-cli](https://git.cflmy.cn/cflmy/marqdo-cli) | 语言规范、Rust 解释器、CLI、运行权限和公开协议 |
|
||||
| [marqdo-extension-conformance](https://git.cflmy.cn/cflmy/marqdo-extension-conformance) | 用冻结的真实 CLI 独立验收包、插件、Provider、Foreign 和 Tool |
|
||||
| [marqdo-knowledge](https://git.cflmy.cn/cflmy/marqdo-knowledge) | 使用公开 Analysis 编译、索引和检索知识文档 |
|
||||
| [marqdo-prove](https://git.cflmy.cn/cflmy/marqdo-prove) | 处理证明依赖、Lean 证书与独立重放 |
|
||||
| [marqdo-view](https://git.cflmy.cn/cflmy/marqdo-view) | 阅读和预览文档、显示执行观察、静态导出 |
|
||||
| [marqdo-lint](https://git.cflmy.cn/cflmy/marqdo-lint) | 静态规则、诊断定位与显式修复 |
|
||||
|
||||
### 独立产品
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-site](https://git.cflmy.cn/cflmy/marqdo-site) | 官网、入门文档、静态站点构建与托管 |
|
||||
| [marqdo-vscode](https://git.cflmy.cn/cflmy/marqdo-vscode) | VS Code 文件关联、编辑体验、CLI 集成与 VSIX 发布 |
|
||||
|
||||
### 标准库
|
||||
|
||||
标准库组件负责低层通用能力,验收后共同组成基础发行的标准库 Bundle。`stdlib/` 的子模块固定各独立仓库的开发提交,状态为 `planned`。 [标准库目录](stdlib/README.md)
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-std-core](https://git.cflmy.cn/cflmy/marqdo-std-core) | Result 与基础数值 |
|
||||
| [marqdo-std-collections](https://git.cflmy.cn/cflmy/marqdo-std-collections) | List、Map 和 Table 值操作 |
|
||||
| [marqdo-std-text](https://git.cflmy.cn/cflmy/marqdo-std-text) | Unicode 文本、字节值与 UTF-8 |
|
||||
| [marqdo-std-encoding](https://git.cflmy.cn/cflmy/marqdo-std-encoding) | Base64、Base32 和 Hex |
|
||||
| [marqdo-std-data](https://git.cflmy.cn/cflmy/marqdo-std-data) | JSON、CSV、TOML 与 GFM 数据转换 |
|
||||
| [marqdo-std-io](https://git.cflmy.cn/cflmy/marqdo-std-io) | Console、Stream、格式化和官方 print 别名 |
|
||||
| [marqdo-std-fs](https://git.cflmy.cn/cflmy/marqdo-std-fs) | 文件、目录与路径 |
|
||||
| [marqdo-std-system](https://git.cflmy.cn/cflmy/marqdo-std-system) | 时钟、UTC、环境、进程与随机 |
|
||||
| [marqdo-std-net](https://git.cflmy.cn/cflmy/marqdo-std-net) | TCP、UDP、TLS 和网络字节流 |
|
||||
|
||||
### 领域扩展
|
||||
|
||||
领域扩展负责按需安装的算法、协议和业务能力。`extensions/` 的子模块链接各独立仓库,功能从 `planned` 状态开始开发。 [领域扩展目录](extensions/README.md)
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-ext-math](https://git.cflmy.cn/cflmy/marqdo-ext-math) | 数值算法、统计、符号数学及绘图 |
|
||||
| [marqdo-ext-linalg](https://git.cflmy.cn/cflmy/marqdo-ext-linalg) | 复数、矩阵、分解及数值线性代数 |
|
||||
| [marqdo-ext-quantum](https://git.cflmy.cn/cflmy/marqdo-ext-quantum) | 量子电路、态向量、采样与模拟 |
|
||||
| [marqdo-ext-http](https://git.cflmy.cn/cflmy/marqdo-ext-http) | HTTP、URL、SSE 与报文生命周期 |
|
||||
| [marqdo-ext-websocket](https://git.cflmy.cn/cflmy/marqdo-ext-websocket) | WebSocket 握手、帧与连接语义 |
|
||||
| [marqdo-ext-ai](https://git.cflmy.cn/cflmy/marqdo-ext-ai) | 模型协议、流式输出与工具调用数据 |
|
||||
| [marqdo-ext-mcp](https://git.cflmy.cn/cflmy/marqdo-ext-mcp) | MCP 协议、传输、发现和调用 |
|
||||
| [marqdo-ext-crypto](https://git.cflmy.cn/cflmy/marqdo-ext-crypto) | 成熟密码学实现的封装 |
|
||||
| [marqdo-ext-database](https://git.cflmy.cn/cflmy/marqdo-ext-database) | SQL 参数绑定、事务和驱动连接 |
|
||||
| [marqdo-ext-storage](https://git.cflmy.cn/cflmy/marqdo-ext-storage) | 本地和对象存储接口 |
|
||||
| [marqdo-ext-cache](https://git.cflmy.cn/cflmy/marqdo-ext-cache) | TTL、缓存和失效 |
|
||||
| [marqdo-ext-security](https://git.cflmy.cn/cflmy/marqdo-ext-security) | 应用身份、会话及权限模型 |
|
||||
| [marqdo-ext-browser](https://git.cflmy.cn/cflmy/marqdo-ext-browser) | 浏览器宿主、WASM 适配、DOM 和事件 |
|
||||
| [marqdo-ext-document](https://git.cflmy.cn/cflmy/marqdo-ext-document) | Markdown 结构与显式文档编辑 |
|
||||
| [marqdo-ext-archive](https://git.cflmy.cn/cflmy/marqdo-ext-archive) | 压缩、安全归档和解包 |
|
||||
| [marqdo-ext-engineering](https://git.cflmy.cn/cflmy/marqdo-ext-engineering) | 工程操作、文件补丁与产物 |
|
||||
| [marqdo-ext-regex](https://git.cflmy.cn/cflmy/marqdo-ext-regex) | 正则匹配、捕获、扫描和替换 |
|
||||
| [marqdo-ext-datetime](https://git.cflmy.cn/cflmy/marqdo-ext-datetime) | IANA 时区、DST 和高级日历 |
|
||||
|
||||
### Web 领域聚合
|
||||
|
||||
Web 领域以设计文档为源材料,面向可交互的原型预览与工程交付。HTTP、数据库、认证和浏览器运行时各自独立维护。`extensions/web` 链接 `planned` 的 Web 领域仓,Design 和 Preview 由该领域仓固定。 [WEB-DESIGN](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md)
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web) | Web 领域聚合:唯一设计合同、示例、组合验收与交付协调,不含生产实现 |
|
||||
| [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) | 设计文档解释、校验、组件/依赖图、诊断与 handoff(独立 Rust library) |
|
||||
| [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview) | 通用离线预览渲染、有限状态交互与 `web` Tool 发行 |
|
||||
|
||||
## 参与开发
|
||||
|
||||
在负责的独立仓库提交实现和测试。主仓库用 Git 子模块按“根 → 领域 → 功能”最多两级固定提交,组件的发行状态由 catalog 独立记录。需要获取当前组合时,运行:
|
||||
|
||||
```sh
|
||||
git clone https://git.cflmy.cn/cflmy/marqdo.git
|
||||
cd marqdo
|
||||
git submodule update --init --recursive
|
||||
python3 scripts/check-layout.py --checkouts
|
||||
python3 -m unittest discover -s tests/integration
|
||||
```
|
||||
|
||||
`check-layout.py` 校验每层 catalog、gitlink、权威远端、全局 ID 和依赖图。`--checkouts` 同时核对递归检出的实际提交。`planned` 子模块提供固定开发快照,只有 `active` 组件进入发行验收。
|
||||
|
||||
[各仓库任务](docs/REPOSITORY-TASKS.md) · [组件目录](components.toml) · [架构边界](docs/ARCHITECTURE.md) · [开发流程](docs/DEVELOPMENT.md) · [迁移台账](docs/MIGRATION.md) · [架构决策记录](docs/adr/README.md) · [AGENTS](AGENTS.md)
|
||||
|
||||
旧版实现与文档可在历史标签查阅。 [v2.9.1 历史树](https://git.cflmy.cn/cflmy/marqdo/src/tag/v2.9.1)
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
title: Marqdo主分支开发记录
|
||||
date: 2026-08-11
|
||||
author: pingan
|
||||
---
|
||||
|
||||
## 前言
|
||||
在经过一周多的ai疯狂开发之后,尽管marqdo已经做出了并拥有了许多非常良好的特性,作者确逐渐感到非常的不安,
|
||||
这种不安来自于崩塌感,作者不知道什么时候,ai就会更改关键的定义,导致突然的崩塌,在开发智能体拓展库的时候作者还尚未有这种感觉,但是在网络拓展库,这种不安定感几乎席卷了作者的全部身心。
|
||||
|
||||
必须承认,ai在没有经过大量训练就撰写一门崭新的语法,定义一些它完全没有接触过的东西对于ai还是太困难了,ai并不能通过我的监督,真正的理解marqdo代码即文档的设计思路,所以,尽管非常的遗憾,作者还是决定回归古法编程,还是手搓代码吧,尽管这意味着marqdo很难赶上ai的浪潮了。
|
||||
|
||||
marqdo的设计初衷很是简单,这就不是一门设计给程序员的语言,哪个程序员会用markdown表格来表示集合呢?不会的,这太过繁复了,但是ai可以,这就使得过去编程语言的范式变得不是那么重要了。
|
||||
|
||||
自然如果只是为了易读性,marqdo并没有完全的开发必要,重点在于对md的支持,作者必须承认谷歌提出的OKF规范,把markdown这种文件格式放到了一个极高的位置,这意味着,可执行的知识体系,如果能做到,为什么不试试?
|
||||
|
||||
此外,jupyter notebook笔记本体积太大不利于管理的问题也是存在的,作者就在想,markdown支持代码块的插入,这个代码如果可以直接执行并放回,这不就是最好的jupyter替代品吗?事实上,在main分支的marqdo已经实现了这个功能,但是还不够好,作者要把marqdo真正做成一门科学计算的顶级语言。
|
||||
|
||||
最后是数学公式的支持,公式库需要能够自动的渲染,高可读,还要能够自动的画图,自动的完成诸多内容,让可执行=正确,让ai支持数学推理不再困难。
|
||||
|
||||
最后,2026年8月11日,我预祝未来的自己,开发成功。
|
||||
|
||||
## 开发
|
||||
|
||||
### Marqdo上下文无关文法
|
||||
|
||||
file -> "---" metadata "---" content ;
|
||||
|
||||
metadata -> file_information |
|
||||
import_lib_name ;
|
||||
|
||||
content -> comment |
|
||||
code_body ;
|
||||
|
||||
comment -> comment_content ;
|
||||
|
||||
code_body -> class |
|
||||
function|
|
||||
code|
|
||||
$formula$|$$formula$$|\[formula\]|
|
||||
```code_block_type
|
||||
code_block
|
||||
```;
|
||||
|
||||
class -> # class_name code_body |
|
||||
# class_name => parent_class_name code_body ;
|
||||
|
||||
function -> function_header param_list body return_stmt ;
|
||||
|
||||
function_header -> ## identifier |
|
||||
### identifier |
|
||||
#### identifier ;
|
||||
|
||||
param_list -> + identifier ;
|
||||
|
||||
body -> statement |
|
||||
branch |
|
||||
loop ;
|
||||
|
||||
return_stmt -> ** statement ** ;
|
||||
|
||||
<!--the number of # stand for the level of function -->
|
||||
|
||||
code -> 1. branch |
|
||||
- loop |
|
||||
statement ;
|
||||
|
||||
<!--Ordered lists represent branch, unordered lists represent loop-->
|
||||
|
||||
branch -> statement ;
|
||||
|
||||
loop -> statement ;
|
||||
|
||||
statement -> > call |
|
||||
literal|
|
||||
`var_value_name`|
|
||||
list and dict|
|
||||
"str"|
|
||||
*statement_without_any_marker*;
|
||||
|
||||
<!--here we use markdown table to stand for list and dict-->
|
||||
|
||||
call -> function_name args;
|
||||
|
||||
literal -> literal_code as other code;
|
||||
|
||||
formula -> latex math code;
|
||||
|
||||
code_block_type -> code_block's code type;
|
||||
|
||||
code_block -> code of a code_block;
|
||||
-1
Submodule cli deleted from deadf6edee.
-393
@@ -1,393 +0,0 @@
|
||||
# 生态组件职责与构建关系。精确提交由 Git tree 的 gitlink 锁定。
|
||||
# 治理树最多两级:根 → 领域聚合(kind = "domain")→ 功能组件。每个聚合仓库只登记直属子组件,
|
||||
# 递归展平后全局 ID 与权威远端唯一;禁止在根同时登记某个计划中聚合及其后代路径。
|
||||
# kind = "domain" 是治理角色:requires = [],release 为 none(普通领域)或 base(Stdlib Bundle 聚合),
|
||||
# 聚合仓自身不含生产实现;其子组件在领域仓库自己的 components.toml 登记。
|
||||
# planned 的 requires 是设计输入,激活前须核对实际 imports 和发布依赖。
|
||||
# 已发布的仓库提交可以作为 planned gitlink 固定,发行验收以 active 状态为准。
|
||||
|
||||
[[component]]
|
||||
id = "cli"
|
||||
path = "cli"
|
||||
kind = "core"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "语言语义、运行时、受控宿主和公共协议"
|
||||
requires = []
|
||||
checks_with = ["conformance"]
|
||||
release = "base"
|
||||
entry = "tools/release/smoke.py"
|
||||
|
||||
[[component]]
|
||||
id = "conformance"
|
||||
path = "tests/conformance"
|
||||
kind = "test"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "可执行的独立公共协议测试"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "none"
|
||||
entry = "scripts/build_all.sh"
|
||||
|
||||
[[component]]
|
||||
id = "view"
|
||||
path = "tools/view"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "阅读、运行观察与静态导出"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/acceptance.sh"
|
||||
|
||||
[[component]]
|
||||
id = "knowledge"
|
||||
path = "tools/knowledge"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "静态知识编译与检索"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/ci.sh"
|
||||
|
||||
[[component]]
|
||||
id = "prove"
|
||||
path = "tools/prove"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "证明依赖、证书及 Lean 后端"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/package-tool.sh"
|
||||
|
||||
[[component]]
|
||||
id = "lint"
|
||||
path = "tools/lint"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "静态规则、诊断及显式修复"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/package-tool.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-core"
|
||||
path = "stdlib/core"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Result 与基础数值"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
|
||||
[[component]]
|
||||
id = "std-collections"
|
||||
path = "stdlib/collections"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "List、Map 和 Table 值操作"
|
||||
requires = ["cli"]
|
||||
checks_with = ["std-data"]
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-text"
|
||||
path = "stdlib/text"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "Unicode 文本、字节值与 UTF-8"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-encoding"
|
||||
path = "stdlib/encoding"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Base64、Base32 和 Hex"
|
||||
requires = ["cli", "std-core", "std-text"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
|
||||
[[component]]
|
||||
id = "std-data"
|
||||
path = "stdlib/data"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "JSON、CSV、TOML 与 GFM 数据转换"
|
||||
requires = ["cli"]
|
||||
checks_with = ["std-collections"]
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-io"
|
||||
path = "stdlib/io"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "Console、Stream、格式化和官方 print 别名"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-fs"
|
||||
path = "stdlib/fs"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "文件、目录与路径"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-system"
|
||||
path = "stdlib/system"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "时钟、UTC、环境、进程与随机"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-net"
|
||||
path = "stdlib/net"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "TCP、UDP、TLS 和网络字节流"
|
||||
requires = ["cli", "std-io", "std-system"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
|
||||
[[component]]
|
||||
id = "math"
|
||||
path = "extensions/math"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "数值算法、统计、符号数学及绘图"
|
||||
requires = ["cli", "std-core", "std-collections", "std-text"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "linalg"
|
||||
path = "extensions/linalg"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "复数、矩阵、分解及数值线性代数"
|
||||
requires = ["cli", "math"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "quantum"
|
||||
path = "extensions/quantum"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "量子电路、态向量、采样与模拟"
|
||||
requires = ["cli", "linalg"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "http"
|
||||
path = "extensions/http"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "HTTP、URL、SSE 与报文生命周期"
|
||||
requires = ["cli", "std-net", "std-text", "std-encoding"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "websocket"
|
||||
path = "extensions/websocket"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "WebSocket 握手、帧与连接语义"
|
||||
requires = ["cli", "http"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "ai"
|
||||
path = "extensions/ai"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "模型协议、流式输出与工具调用数据"
|
||||
requires = ["cli", "http", "std-data"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "mcp"
|
||||
path = "extensions/mcp"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "MCP 协议、传输、发现和调用"
|
||||
requires = ["cli", "http", "std-system"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "crypto"
|
||||
path = "extensions/crypto"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "成熟密码学实现的封装"
|
||||
requires = ["cli", "std-encoding"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "database"
|
||||
path = "extensions/database"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "SQL 参数绑定、事务和驱动连接"
|
||||
requires = ["cli", "std-data"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "storage"
|
||||
path = "extensions/storage"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "本地和对象存储接口"
|
||||
requires = ["cli", "std-fs"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "cache"
|
||||
path = "extensions/cache"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "TTL、缓存和失效"
|
||||
requires = ["cli", "std-system"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "security"
|
||||
path = "extensions/security"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "应用身份、会话及权限模型"
|
||||
requires = ["cli", "crypto", "http"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "web"
|
||||
path = "extensions/web"
|
||||
kind = "domain"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Web 原型设计领域治理:唯一设计合同、组合验收与交付协调"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "none"
|
||||
|
||||
[[component]]
|
||||
id = "browser"
|
||||
path = "extensions/browser"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "浏览器宿主、WASM 适配、DOM 和事件"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "document"
|
||||
path = "extensions/document"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Markdown 结构与显式文档编辑"
|
||||
requires = ["cli", "std-fs", "std-text"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "archive"
|
||||
path = "extensions/archive"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "压缩、安全归档和解包"
|
||||
requires = ["cli", "std-text", "std-fs"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "engineering"
|
||||
path = "extensions/engineering"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "工程操作、文件补丁与产物"
|
||||
requires = ["cli", "document", "archive"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "regex"
|
||||
path = "extensions/regex"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "正则匹配、捕获、扫描和替换"
|
||||
requires = ["cli", "std-text"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "datetime"
|
||||
path = "extensions/datetime"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "IANA 时区、DST 和高级日历"
|
||||
requires = ["cli", "std-system"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
@@ -1,105 +0,0 @@
|
||||
# 架构与所有权
|
||||
|
||||
自建 Git `git.cflmy.cn/cflmy` 是代码、工单和合并的权威,`ci.cflmy.cn` 是 CI 权威,GitHub 仅作镜像或分发渠道。主仓库维护生态组件关系、精确组合、跨组件验收、发行与责任治理;领域聚合仓库维护本领域的合同与组合验收;功能仓库拥有唯一实现、测试和缺陷修复。
|
||||
|
||||
## 三种关系,不得混用
|
||||
|
||||
| 关系 | 表达载体 | 用途 | 约束 |
|
||||
| --- | --- | --- | --- |
|
||||
| 治理树 | `.gitmodules` + Git tree gitlink + 每层 `components.toml` | 源码归属、父级与提交身份 | 每个组件只有一个父级;全局 ID 与权威远端唯一;Gitlink 是提交身份唯一权威,`.gitmodules` 是权威远端唯一记录 |
|
||||
| 构建/制品依赖 DAG | `requires` 与真实 package/Cargo/Tool/Bundle 依赖 | 编译、打包、发行装配顺序 | 可以跨治理树;必须有向无环;聚合节点不是可被程序 import 的包 |
|
||||
| 协同验收关系 | `checks_with` | 跨组件测试与消费者回归 | 不是安装依赖;允许互相测试;调度固定点必须去重且不得互相等待形成死锁 |
|
||||
|
||||
组件关系不能由目录物理位置推导,也不能把兄弟仓库的源码路径当作公开依赖。`requires` 只表达真实直接构建或制品依赖,禁止把计划假想写成实际依赖。
|
||||
|
||||
## 治理树与分层
|
||||
|
||||
治理树最多两级 Gitlink:**根仓库 → 领域聚合仓库 → 功能仓库**(主仓库→领域→功能,深度 2)。新增三级 gitlink 需要生态 ADR 和真实跨仓维护收益,默认拒绝。目录层级不等于运行时依赖层级。
|
||||
|
||||
- **领域(`kind = "domain"`)**:工程治理角色,不是语言层也不是运行协议。领域仓库只登记直属子组件,可拥有 `components.toml`、`.gitmodules`、领域公共规范、跨组件集成测试、综合示例、发布装配脚本、ADR 与维护指南;禁止在其中建立 renderer、解析器、数据库驱动等生产实现,也禁止把子仓库源码复制进普通目录。领域 `requires = []`,`release` 为 `none`(普通领域)或 `base`(Stdlib Bundle 聚合)。
|
||||
- **功能组件**:`kind` 仍为 `core/stdlib/extension/tool/test`,在责任仓库独立实现、测试和发版;`release` 与 `kind` 的对应关系不变(base/optional/none)。
|
||||
- **唯一归属**:一个功能只有一个权威实现,一个组件只有一个治理归属,一个公共边界只有一套现行合同。已有仓库直接复用,不能因为命名不符创建重复实现。
|
||||
- **`planned` 纪律**:已有仓库可以通过 gitlink 固定已发布的开发提交。尚无提交的仓库登记在 [迁移台账](MIGRATION.md)。组件通过联合验收后才晋升为 `active` 并登记实际 `entry`。将直属组件迁入领域时,在同一根候选转移清单和 gitlink,保证一个组件只有一个父级。
|
||||
- **聚合准入**:功能拆分须至少有一种独立价值(独立维护责任、显著不同依赖/安全/平台边界、独立版本与制品、可重复独立验收)。若两个仓库几乎每个 PR 都必须一起改动且接口未稳定,应先收敛合同或合并,不能无限拆分。
|
||||
- **工具目录**(`tools/`)暂不聚合,现有四个 Tool 保持原路径。
|
||||
|
||||
**当前状态**(以 [components.toml](../components.toml) 与 [迁移台账](MIGRATION.md) 为准):根仓库有六个核心/工具 active 组件(`cli`、`conformance`、`view`、`knowledge`、`prove`、`lint`)和六个已交付源码的 active 标准库组件(`std-collections/data/fs/io/system/text`)。`std-core/encoding/net` 与十八个独立扩展仍是根层 planned 子模块。`extensions/web` 是 planned 领域子模块,Design 和 Preview 由 Web 领域仓挂载。`marqdo-stdlib` 聚合和 `web-components` 仍在计划中。
|
||||
|
||||
## 语言与产品层(不因仓库变多而改变)
|
||||
|
||||
| 层 | 权威所有者 | 允许 | 禁止 |
|
||||
| --- | --- | --- | --- |
|
||||
| L0 语言核心 | CLI | Markdown 映射、AST、IR、Value、Memory、求值 | Web/AI/数据库专属关键字 |
|
||||
| L1 平台能力 | CLI Capability Host | 权限、预算、通用资源/扩展机制 | 网页布局和业务协议 |
|
||||
| L2 标准库 | Stdlib 各功能仓库 | 基础发行默认安装的通用低层算法及薄封装 | 依赖领域扩展或大型专业运行环境 |
|
||||
| L3 扩展 | 各领域功能仓库 | 可选专业算法、协议和资源后端 | 修改或复制语言内核 |
|
||||
| L4 应用 | 用户项目 | 使用已发布能力实现具体任务 | 作为默认基础发行依赖 |
|
||||
| Tool(旁路) | 独立工具 | 通过公开 CLI 协议处理源码、分析及制品 | 伪装成 Runtime 插件,反向侵入核心 |
|
||||
|
||||
## 权威记录与递归校验
|
||||
|
||||
每个拥有子模块的聚合仓库只登记直接子组件;普通功能仓库不需要另建治理清单。配置与身份的唯一来源:
|
||||
|
||||
| 记录 | 权威内容 |
|
||||
| --- | --- |
|
||||
| `components.toml`(每层) | 组件 ID、父级路径、kind、state、owner、scope、`requires`、`checks_with`、release、active 入口 |
|
||||
| `.gitmodules`(每层) | 直属子组件权威远端 |
|
||||
| Git tree gitlink | 精确提交身份 |
|
||||
| Cargo.lock / `marqdo.lock` / 现行 Bundle manifest | 相应依赖与制品身份 |
|
||||
|
||||
主仓库 `scripts/check-layout.py` 校验 catalog、gitlink、远端与文件白名单。`--checkouts` 递归读取每个已挂载领域的固定提交,逐层验证 gitlink、远端、工作树和活跃入口,并检查全局 ID、依赖边界和无环性。CI 用 `--domain-paths` 在检出子组件前校验领域远端。 [开发流程](DEVELOPMENT.md)
|
||||
|
||||
## 各领域排他边界
|
||||
|
||||
| 领域 / 功能 | 应拥有 | 不应拥有 |
|
||||
| --- | --- | --- |
|
||||
| Stdlib/Core、Collections、Text、Encoding、Data、IO、FS、System、Net | 默认安装的通用低层能力及薄封装 | 专业计算、外部服务、HTTP 协议 |
|
||||
| Ext-Net(HTTP/WebSocket) | URL、HTTP 客户端/服务端协议、SSE、Cookie、Multipart、WebSocket 帧与生命周期 | Web 页面模型、应用实时协作状态 |
|
||||
| Web 领域 | 设计模型、快速预览、交付清单与组件复用 | 生产级前端框架、HTTP/DB/认证协议、AI 调度 |
|
||||
| Browser | 将来可选的真实浏览器执行宿主与平台桥 | 本期 Web 原型必需依赖、第二套解释器 |
|
||||
| AI / MCP | 模型访问、流式结果、工具调用数据;MCP 发现/调用/传输 | 全量 Agent 调度、HTTP 实现、Agent 框架 |
|
||||
| Database / Storage / Cache / Auth | 参数化查询与事务、存储接口、TTL 缓存、OIDC/会话/RBAC | Web 后台页面、文件系统原语、替代 Capability Host |
|
||||
| Crypto / Datetime / Regex / Archive | 成熟密码学封装、IANA 时区、完整正则、安全归档 | 自制不安全加密、重复宿主基础原语 |
|
||||
| Document / Engineering | 文档显式编辑、工程操作与产物 | 静态分析或编辑器全栈平台 |
|
||||
| Quantum / Linalg / Math | 量子态/电路/模拟、矩阵/张量/分解、数值与符号数学 | 复制矩阵内核、通用前端框架 |
|
||||
|
||||
上表是规划边界,不是开发完成承诺。旧标准库中 `net/http.mq.md`、`regex.mq.md`、`compress.mq.md` 的迁移必须有真实替代实现与验收才能退出原归属,不得先删造成回归,也不得长期维护两个官方实现。
|
||||
|
||||
## Web 领域
|
||||
|
||||
Web 领域的产品定义是**文档原生、可交互的前端设计原型及工程交付**,不是新的通用前端框架。GFM 表描述组件关系,普通 Markdown 描述内容与意图,链接表达精确的组件引用与设计依赖,有限场景表达交互原型;生产级前端由成熟框架完成。HTTP、数据库、认证、浏览器运行时仍是独立通用能力,不是原型工具的强制依赖。
|
||||
|
||||
- **唯一作者合同**:[marqdo-ext-web 的 WEB-DESIGN](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md)。主仓库、组件仓库和作者文档都引用它,不并列维护第二份现行合同;合同变更在该领域走 ADR 并与 Design/Preview 同候选验证。
|
||||
- **领域聚合** `marqdo-ext-web`(planned):治理、合同、示例、组合验收;无运行时入口,不实现 renderer/parser。
|
||||
- **Web Design** `marqdo-web-design`(planned):独立 Rust library,唯一解释作者合同、消费真实 CLI Analysis、产出设计模型/诊断/handoff;不启动服务、不渲染 DOM、不复制 CLI parser。
|
||||
- **Web Preview** `marqdo-web-preview`(planned):独立 executable + `tool.json`,注册唯一 `web` 命令;消费 Design 公开 API,生成离线安全预览与有限状态交互;不自行解释表格、不写任务专用 JS、不启动生产服务器。
|
||||
- **组件模板** `web-components`:候选,只有至少两个独立真实复用模板及稳定合同后才准入,不阻塞首版。
|
||||
- **边界**:首版不迁移 WASM、不重新实现语言、不要求旧 plugin 回调,不新增 CLI Web 关键字或 `@component` 语义;复杂视觉、真实登录/支付/数据库/网络和任意状态管理交给生产实现。Web 领域已通过 gitlink 固定开发提交,状态为 `planned`。 [开发流程](DEVELOPMENT.md)
|
||||
|
||||
## 新增能力与公共边界
|
||||
|
||||
先复用职责匹配的组件。需要独立维护、依赖、安全或发行边界时,为新仓库发起评审;加入标准库须证明基础发行默认需要、至少三个领域真实复用、依赖闭包受控,并说明错误、授权和预算语义。
|
||||
|
||||
需要新增 builtin、HostOp、值类型、语法或公共协议字段时,在 CLI 提交 ADR,写明现有机制为何不足、最小复现、三个领域用例、替换及正负例。Web 专属需求不得进入 CLI 核心;设计领域能自己解释的内容留在 Web 合同。公开接口破坏性更新按同一候选组合切换产生者和消费者,保留单套现行协议;历史行为通过固定版本的历史发行复现。
|
||||
|
||||
## 架构门禁
|
||||
|
||||
| 门禁 | 检查与拒绝条件 | 权威 |
|
||||
| --- | --- | --- |
|
||||
| 归属唯一 | Git tree/catalog 递归一致,一个全局 ID 与远端只出现一次,不允许同功能两个官方实现 | 根 |
|
||||
| 聚合纯度 | 根与领域聚合不含生产实现;新增文件须落在治理/集成/示例职责 | 根/领域 |
|
||||
| 深度 | 超过两级 Gitlink 拒绝,除非批准 ADR 先更新单一规则 | 根 |
|
||||
| 真实依赖 | active 不依赖 planned;requires DAG 无环;无父 checkout 或跨仓私有源码依赖 | 根/组件 |
|
||||
| 标准库准入 | 基础发行默认必需、低层、至少三类真实消费者、依赖与授权有界;新功能默认 extension | Stdlib/根 |
|
||||
| 内核准入 | 新 builtin/HostOp/语法/协议字段须 ADR、最小复现、三个不相关领域用例;Web 专属需求不进入 CLI | CLI |
|
||||
| Web 作者面 | 不新增核心语法、重复表头方言、隐式解析普通文档、HTML 注入默认通道 | Ext-Web/Design |
|
||||
| 通用渲染 | 新普通组件由设计文档复用实现;不得新增任务/页面/业务专用 renderer 分支 | Preview |
|
||||
| 原型诚实性 | 模拟明确标注;无真实后端、无假执行、无伪造生产测试 | Web |
|
||||
| 独立产品 | 组件能独立构建;只有实际产品需要才创建新仓库 | 各级 |
|
||||
| 现行合同唯一 | 不引入旧协议 fallback、版本数组、旧语法探测;配对候选一次切换 | 各级 |
|
||||
| 默认安装规模 | 基础制品不引入可选 Tool/领域环境;体积、构建时间及依赖增长记录基线 | 根/Stdlib |
|
||||
| 范围控制 | 每个 PR 关联责任工单、复现与验收;无关重构拆独立任务 | 各级 |
|
||||
|
||||
每次架构变更须回答:谁是唯一责任方?是否必须新增公开边界?如何证明现有机制不足?能否在单仓修复?新功能能否独立测试?删除或替代了什么?回答不明确则不进入开发。
|
||||
|
||||
跨组件测试以真实 CLI/Worker、独立消费者和现行权限配置验证。Native 后端与外部工具按 CLI 安全边界执行,权限、隔离和预算声明以可验证的实际行为为准。
|
||||
@@ -1,101 +0,0 @@
|
||||
# 开发、验收与发行
|
||||
|
||||
生态采用**逐层候选晋升**:功能仓库修实现,领域聚合仓库固定组合并做领域验收,主仓库固定整个递归树并做生态验收。任何一层失败都停在该层,不让未验证组合进入受保护的分支;回退根 gitlink 即可复现上一个已接受组合,不重写子仓库历史。
|
||||
|
||||
## 责任仓库与工单
|
||||
|
||||
1. 先确定唯一责任仓库:功能行为在功能仓库;领域合同、示例与组合在领域聚合仓库;gitlink、跨领域集成、发行组合与治理在主仓库。拿不准时按“第一个违反公开合同的所有者”定责,而不是按错误最后显示的仓库。
|
||||
2. 在责任仓库找到或建立工单,按 `.gitea/ISSUE_TEMPLATE/change.md` 记录:责任组件与类型、影响消费者、根/领域/组件 SHA、CLI 与依赖制品摘要及平台、最小 fixture 与命令、实际与预期结果、权威合同链接、修复范围、验收命令。
|
||||
3. 跨仓库阻塞在上游仓库开工单,并在消费者工单记录回归条件;不同问题拆分,重复发现追加证据。任何维护者或 AI 都可以读其它仓库定位,但修改必须进入对应责任仓库的独立提交。
|
||||
|
||||
## 分层候选流程
|
||||
|
||||
以 Web 领域为例,一般组件同理:
|
||||
|
||||
```text
|
||||
功能提交 C2(功能仓库,通过组件 CI)
|
||||
-> 领域 PR 将 gitlink 更新到 C2,通过领域 CI,形成 B2
|
||||
-> 主仓库 PR 将领域 gitlink 更新到 B2,通过根递归校验与受影响组合验收,形成 A2
|
||||
```
|
||||
|
||||
- 子模块的 detached HEAD 只用于复现与集成;开发应在子仓库独立创建分支后推送,禁止 `git submodule update --remote` 在发布/验收中追踪浮动分支。
|
||||
- 同一份公共合同切换需要多个组件同步变化时,在一个候选组合中提交整组 gitlink,配对候选联调通过后再晋升;不允许主分支出现半套协议。
|
||||
- 领域激活(planned → active)的门禁:两个功能仓具备真实 `entry` 与候选提交,领域 `components.toml` 与 gitlink 一致,领域 CI 和根递归校验通过,Design/Preview 等有依赖关系的组件获得同候选证据。已发布的开发提交可先作为 `planned` 子模块固定。
|
||||
|
||||
## 递归校验与组合检查
|
||||
|
||||
```sh
|
||||
git submodule update --init --recursive
|
||||
python3 scripts/check-layout.py # 根层:catalog/gitlink/远端/白名单
|
||||
python3 scripts/check-layout.py --checkouts # 递归:各 active 领域固定提交、全局图与依赖
|
||||
python3 -m unittest discover -s tests/integration
|
||||
bash scripts/integration.sh # 生态候选:真实 CLI 制品 + 组件验收
|
||||
```
|
||||
|
||||
- 校验器读取 Git tree 中固定提交的 catalog,不以工作区改动替代候选;`--checkouts` 需要子模块已初始化,缺失、错误 HEAD、脏工作区、错误入口都明确 FAIL/UNVERIFIED,不静默跳过。CI 先验证并检出直属子模块,再用 `--domain-paths` 校验领域的子模块远端,最后逐个领域检出直属子库。
|
||||
- 没有 active 领域时,新校验规则同样接受合法的直属功能组件,这不是历史协议兼容。
|
||||
- 未知的 active 入口、未声明的 gitlink、目录与 catalog 不一致都必须让候选失败。`planned` 不进入验收计数。
|
||||
- 当前 CI 为 `layout` 与 `candidate` 两段;统一 CLI 制品准备、声明驱动调度与递归影响分析仍在推进(见 `.woodpecker/eco.yml` 与主仓库工单),不得以本文件描述当作已实现。
|
||||
|
||||
## 三层验收
|
||||
|
||||
| 层 | 责任与证据 |
|
||||
| --- | --- |
|
||||
| C1 组件 CI | 责任组件独立检出、独立构建与测试、授权负例、固定依赖、打包 smoke;由组件仓库维护 |
|
||||
| C2 公共契约 | 真实 CLI 和 Worker、独立 Conformance 与消费者,覆盖当前协议、失败和正确身份 |
|
||||
| C3 生态集成 | 递归结构校验、公开冷克隆、精确 gitlink、官方基础发行、CLI Tool 与契约消费回归 |
|
||||
|
||||
三层不是重复跑三次测试:同一候选、同一制品、同一环境的有效证据可以复用;身份不匹配必须重跑。每个 active 组件提供独立验收入口(建议 `scripts/ci.sh` 或 `scripts/integration.sh`),从显式传入的 `MARQDO_BIN`、Bundle/依赖制品位置和隔离输出目录读取输入,不自行拉取浮动 CLI 或其它组件 main。
|
||||
|
||||
## 统一 CLI 与制品输入
|
||||
|
||||
- 生态候选使用**固定、可验证**的 CLI/Worker/Stdlib 候选制品;输入必须绑定 CLI gitlink SHA、目标平台、归档/二进制/Bundle digest、工具链与锁。
|
||||
- 标准库 Bundle 的唯一生产者是根仓库的 `scripts/build-stdlib.py`:它从根提交的精确组件 gitlink 读取各 active `kind = "stdlib"` 组件的 `modules/`,校验发布路径(只发布 `.mq.md`、拒绝 symlink/子模块/大小写与 NFC 冲突、`tests/` 不入库),生成现行 `stdlib.json`(tree digest + aliases digest),配置在 `scripts/stdlib-bundle.json`。版本变化必须显式(`--baseline-manifest` 拒绝同版本不同摘要)。组件仓继续拥有源码与测试,根不复制模块。
|
||||
- 组合验收入口是根仓库的 `scripts/acceptance-stdlib.py`:只接受显式 `--cli` 与 `--bundle`(或按根 gitlink 构建),运行各 active 组件的 `entry`、跨仓组合 fixture(别名、Table 切分、默认 Bundle smoke)和必须失败的负例;提供 `--pack-tool` 时用 CLI 自己的打包器做两次确定性打包并核对摘要。CLI 自身打包请使用 Phase A 之后的 `--stdlib-dir` 输入,不再默认读取 CLI 源码树。
|
||||
- 统一制品输入已落地(ECO-02 核心):`scripts/integration.sh` 不再从 View 的冻结脚本取 CLI 制品,而是由同一根候选派生全部输入——根唯一生产者 `scripts/build-stdlib.py` 按固定 gitlink 生成 Bundle;`cli/` 固定提交构建 CLI 与 Worker;`cli/tools/release/package.py --stdlib-dir <Bundle>` 生成发行归档;随后 Conformance、View、Knowledge、Prove、Lint 与根 `acceptance-stdlib.py` 全部使用同一安装后二进制与相邻 Bundle。任何消费者都不能决定 CLI 版本,也不再有浮动或隐式制品。
|
||||
- 组件验收只读取传入制品,不自行下载未知版本;开发目录覆盖入口(如 `MARQDO_STDLIB_DIR`)不得当作发行行为。缺失、摘要不符或平台不符必须拒绝。
|
||||
|
||||
## 影响范围与调度
|
||||
|
||||
根 `scripts/impact.py` 比较已接受根提交与候选递归展开的 `(global_id, parent, remote, SHA, state)`:领域指针变化展开到子组件身份,不能只标记父节点;变更叶子加入集合后,取 `requires` 新旧图并集的反向传递依赖闭包,再加所在祖先领域及 `checks_with` 固定点(协同验收不是构建先决)。领域无法展开(缺对象/检出)时结果标 UNVERIFIED 并**全量**扩大范围,不静默跳过;`--fail-on-unverified` 可把该情形变成硬失败。`integration.sh` 将报告写入候选证据(changed/affected/checks_with/fallback),正式发行仍执行所有 active 组件与完整测试。
|
||||
|
||||
## 工单路由与状态
|
||||
|
||||
| 现象 | 责任归属 |
|
||||
| --- | --- |
|
||||
| 组件表头正确但 Design 未识别 | web-design(若 Analysis 的真实 AST 正确) |
|
||||
| Link 中 `not_loaded` 错误处理 | web-design;若 CLI candidate 违反公开 resolver 合同则 CLI |
|
||||
| 手机布局溢出、场景实例串扰 | web-preview |
|
||||
| 特定设计模板不符合合同 | web-components(激活后)或作者项目,不修改核心 renderer 迎合坏模板 |
|
||||
| Web 设计约定出现冲突 | marqdo-ext-web 协调,Design/Preview 各自提交 |
|
||||
| 真实生产框架渲染/业务错误 | 目标应用仓库,不归 Web 原型 |
|
||||
| SSE 或网络传输错误 | Ext-Net 的 HTTP/WS 或 CLI Resource 真正责任方 |
|
||||
| 固定 SHA 组合构建失败 | 若各组件公开制品正确,由所属聚合/根修复装配,否则责任组件 |
|
||||
|
||||
状态流:`open → triaged → in-progress / blocked → component-verified → integrated`。可用现有 Git 平台标签与关联链接,不设计新工单数据库;阻塞项不能以 mock PASS 关闭。组件 PR 合并后可关闭组件修复工单,但消费者/领域或生态集成任务保留到真实候选组合通过。
|
||||
|
||||
## 自动化权限
|
||||
|
||||
先实现人工触发与 PR/CI 门禁,不开发自动 Agent 管理平台。候选通知的授权校验由根 `scripts/candidate-notify.py` 承担:只接受规范化通知(仓库、类型、head/base SHA、CI 状态与 URL),校验仓库在根图远端允许列表内、提交在本地对象库可达、组件候选的 base 必须是 accepted 根图当前固定的 SHA、CI 为允许主机上的 success 且必须是 https;按 `(repository, head SHA)` 去重,拒绝重放,accepted 基线变化时标记 `revalidate` 并要求重跑门禁;影响范围复用 `scripts/impact.py`,无法确定时全量。校验器只输出计划(`auto_promote=false`、`auto_merge=false`、仅创建候选分支需人工评审),不合并、不推送、不扩权。Webhook 只作通知(记录仓库、完整 SHA、CI URL);上级通过 API 验证存在性、审批与权限后再创建候选 PR,不得自动合入或提升权限。外部不可信 PR、未批准 gitlink 或脚本不得在拥有跨仓库写权限/发版密钥的 runner 中运行;区分只读 checkout/test token、受限 issue/PR token、受保护发布权限。日志不得输出凭证、完整 Analysis 或生产 API key。
|
||||
|
||||
## 发行与回滚
|
||||
|
||||
- 组件可独立 SemVer 发布;领域可发布经过验证的组合制品;根生态 release 固定整个 gitlink 树。独立版本不代表维护多套现行协议。
|
||||
- 每份证据记录根及递归组件 SHA、制品摘要、真实命令、退出码、环境/工具链、日志、测试范围与未验证项。复用现有 manifest/evidence 模式,不复制成新的权威锁。
|
||||
- Git tree 是源码身份权威;Cargo.lock/`marqdo.lock`/现行 Bundle manifest 是对应依赖权威。记录不可变归档校验和、可信来源及获取方法;摘要校验不是发布者身份认证。
|
||||
- 基础发行包含同源 CLI、必需 Worker 与单一标准库 Bundle;不使用浮动 branch/标签名作为发布依据。发布失败保留日志,使用新候选;已有标签和资产保持不可变。回滚用新集成提交恢复上一组通过的 gitlink。
|
||||
|
||||
## Web 领域开发约束
|
||||
|
||||
- 唯一作者合同是 `marqdo-ext-web` 的 `docs/WEB-DESIGN.md`;Design 是唯一解释实现,Preview 不另加解析规则。合同变更在该领域走 ADR,并让 Design/Preview 以配对候选一次切换。
|
||||
- Design 只消费公开 CLI `check --emit` 的 Analysis 3,不复制 Markdown/语言解析器、不依赖 CLI 私有 Rust crate;Preview 只消费 Design 的公开 crate/固定 revision,`,...` 不通过 `../design` 长期路径依赖,最终发布以 `Cargo.lock` 固定真实依赖身份。
|
||||
- 首版不迁移 WASM、不新增 CLI 语义、不要求旧 plugin 回调;模拟状态、原型标识与“未实现真实功能”必须对作者可见。
|
||||
- 真实验收使用真实浏览器 `file://` 制品、真实 CLI 正负例与真实冷安装;原型测试 PASS 不能当作生产测试 PASS。
|
||||
|
||||
## 本地环境
|
||||
|
||||
需要 Linux x86_64/glibc ≥ 2.39、Python 3.11+、Git、Rust、C 编译器和 curl;`integration.sh` 另需 jsonschema 与冻结 CLI 归档。详细命令与组件验收入口见各仓库 `README.md` 与 [各仓库任务](REPOSITORY-TASKS.md)。
|
||||
|
||||
## 迁移台账
|
||||
|
||||
标准库与扩展的现状、历史归属和切换顺序以 [迁移台账](MIGRATION.md) 为准。当前 CLI 内置标准库仍是基础发行的现行权威;`marqdo-stdlib` 聚合与九个功能仓库的迁移完成前,不得声称 Stdlib 拆分完成,也不得先删旧实现造成产品回归。
|
||||
@@ -1,207 +0,0 @@
|
||||
# 迁移台账
|
||||
|
||||
## 权威盘点
|
||||
|
||||
历史主分支最后提交为 `1c55baabd570e18b9da8f9057cef2f848e176690`,v2.9.1 的发布提交为 `ffe06d7afab7acaed87be5ff16edddc37da536a2`。自建 Git 已核验旧标签和主分支。旧实现、文档、示例、测试与工作流以历史提交为迁移资料。[历史主分支末尾](https://git.cflmy.cn/cflmy/marqdo/src/commit/1c55baabd570e18b9da8f9057cef2f848e176690)
|
||||
|
||||
| 已有仓库 | 审计时默认分支 | 发行或证据 |
|
||||
| --- | --- | --- |
|
||||
| [marqdo-cli](https://git.cflmy.cn/cflmy/marqdo-cli) | `master` | v3.0.0-rc.4 |
|
||||
| [marqdo-extension-conformance](https://git.cflmy.cn/cflmy/marqdo-extension-conformance) | `main` | 有独立固定 fixture |
|
||||
| [marqdo-knowledge](https://git.cflmy.cn/cflmy/marqdo-knowledge) | `master` | v0.1.0-beta.3 |
|
||||
| [marqdo-lint](https://git.cflmy.cn/cflmy/marqdo-lint) | `main` | v0.2.0 |
|
||||
| [marqdo-prove](https://git.cflmy.cn/cflmy/marqdo-prove) | `master` | v0.1.0-beta.1 |
|
||||
| [marqdo-view](https://git.cflmy.cn/cflmy/marqdo-view) | `master` | v0.3.0 |
|
||||
| [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web) | `main` | Web 领域聚合,planned;唯一设计合同在 `docs/WEB-DESIGN.md` |
|
||||
| [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) | `main` | Web Design 组件,planned;初始开发文档 |
|
||||
| [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview) | `main` | Web Preview 组件,planned;初始开发文档 |
|
||||
|
||||
CLI gitlink 采用 RC.4 正式发布源码,以匹配冻结归档和现有 View/Lint 契约。
|
||||
其文档后续提交曾用于 Knowledge 的独立 CI;生态候选以自身测试判定实际组合。
|
||||
Conformance 使用 CLI 已固定的真实 fixture 提交。
|
||||
|
||||
## 标准库和扩展目录
|
||||
|
||||
主仓库的 [标准库目录](../stdlib/README.md) 和 [扩展目录](../extensions/README.md) 通过 Git 子模块固定独立仓库的开发提交。Web Design 和 Preview 从 Web 领域聚合仓递归获取。是否参加发行验收以 [组件目录](../components.toml) 与该组件所在层的 catalog 为准。
|
||||
|
||||
**标准库(planned,聚合仓库 marqdo-stdlib 尚未创建)** · [core](https://git.cflmy.cn/cflmy/marqdo-std-core) · [collections](https://git.cflmy.cn/cflmy/marqdo-std-collections) · [text](https://git.cflmy.cn/cflmy/marqdo-std-text) · [encoding](https://git.cflmy.cn/cflmy/marqdo-std-encoding) · [data](https://git.cflmy.cn/cflmy/marqdo-std-data) · [io](https://git.cflmy.cn/cflmy/marqdo-std-io) · [fs](https://git.cflmy.cn/cflmy/marqdo-std-fs) · [system](https://git.cflmy.cn/cflmy/marqdo-std-system) · [net](https://git.cflmy.cn/cflmy/marqdo-std-net)
|
||||
|
||||
**扩展(planned,独立组件)** · [math](https://git.cflmy.cn/cflmy/marqdo-ext-math) · [linalg](https://git.cflmy.cn/cflmy/marqdo-ext-linalg) · [quantum](https://git.cflmy.cn/cflmy/marqdo-ext-quantum) · [http](https://git.cflmy.cn/cflmy/marqdo-ext-http) · [websocket](https://git.cflmy.cn/cflmy/marqdo-ext-websocket) · [ai](https://git.cflmy.cn/cflmy/marqdo-ext-ai) · [mcp](https://git.cflmy.cn/cflmy/marqdo-ext-mcp) · [crypto](https://git.cflmy.cn/cflmy/marqdo-ext-crypto) · [database](https://git.cflmy.cn/cflmy/marqdo-ext-database) · [storage](https://git.cflmy.cn/cflmy/marqdo-ext-storage) · [cache](https://git.cflmy.cn/cflmy/marqdo-ext-cache) · [security](https://git.cflmy.cn/cflmy/marqdo-ext-security) · [browser](https://git.cflmy.cn/cflmy/marqdo-ext-browser) · [document](https://git.cflmy.cn/cflmy/marqdo-ext-document) · [archive](https://git.cflmy.cn/cflmy/marqdo-ext-archive) · [engineering](https://git.cflmy.cn/cflmy/marqdo-ext-engineering) · [regex](https://git.cflmy.cn/cflmy/marqdo-ext-regex) · [datetime](https://git.cflmy.cn/cflmy/marqdo-ext-datetime)
|
||||
|
||||
**Web 领域(planned domain)** · 聚合 [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web)(唯一合同 `docs/WEB-DESIGN.md`)· 子组件 [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) · [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview)
|
||||
|
||||
## 分层治理与领域聚合(2026-11-26 起)
|
||||
|
||||
根 catalog 支持唯一的新增类型 `kind = "domain"`(聚合治理角色),治理树最多两级:**根 → 领域聚合 → 功能组件**。规则要点:
|
||||
|
||||
- 每个拥有子模块的聚合仓库只登记直接子组件;全局 ID 与权威远端唯一;功能仓库仍只有一个父级。Gitlink 是提交身份唯一权威,`.gitmodules` 是权威远端唯一记录。
|
||||
- 聚合仓库可拥有 `components.toml`、`.gitmodules`、领域公共规范、跨组件集成测试、综合示例、发布装配脚本、ADR 与维护指南;**禁止**生产实现与源码复制。
|
||||
- 已有 `planned` 仓的 gitlink 固定真实开发提交。尚无提交的组件只登记计划,激活以后再填写真实 `entry` 并计入完成率。领域及其后代分别登记在各自父仓库。
|
||||
- 领域激活门禁:子组件具备真实入口与候选提交、领域 catalog 与 gitlink 一致、领域 CI 通过、根 `check-layout.py --checkouts` 递归校验通过、存在依赖关系的组件以同候选证据验证。
|
||||
- 主仓库 `scripts/check-layout.py` 已引入 domain 角色与递归校验;统一 CLI 制品准备、声明驱动调度、递归影响分析仍在推进,CI 证据以真实候选为准。
|
||||
|
||||
当前状态:**没有任何 active 领域**。Web 领域为 planned(`extensions/web`,聚合仓 marqdo-ext-web,子组件 design/preview 在其 catalog 登记);标准库聚合 marqdo-stdlib 尚未创建,九个 `std-*` 保持根 catalog 的 planned 直属记录;HTTP/WebSocket 等仍为独立 planned 扩展,等至少两个真实组件形成共同边界后再评估聚合。首批 Web 实施工单为 WEB-00(合同与真实 Analysis 风险探测)、WEB-01(Design)、WEB-02(Preview)、WEB-03(handoff/组件图)、WEB-04(组合案例与框架交付)、WEB-05(根接入与冷安装),WEB-06(components)为候选;工单在对应责任仓库创建。Web 合同语义冲突由 marqdo-ext-web 协调,不回流 CLI 核心。
|
||||
|
||||
## 阶段与阻塞
|
||||
|
||||
| 原分支 | 独立仓库与迁移状态 |
|
||||
| --- | --- |
|
||||
| `gh-pages` | 官网架构、v2.9.1 源内容和部署快照均已迁入 marqdo-site。原分支保留现有公共入口,部署切换以独立托管和路由验收为准。[托管切换工单](https://git.cflmy.cn/cflmy/marqdo-site/issues/1) |
|
||||
| `vscode-extension` | 扩展目录历史归档到 marqdo-vscode 的 `legacy-v2.8.0`。现行 CLI 适配和新版 VSIX 由扩展仓独立开发和验收。[首版实现工单](https://git.cflmy.cn/cflmy/marqdo-vscode/issues/1) |
|
||||
|
||||
| 阶段 | 当前范围 | 后续验收 |
|
||||
| --- | --- | --- |
|
||||
| M0 盘点 | 自建 Git、历史标签、已有六组件和新仓位 | 通过真实远端候选持续维护台账 |
|
||||
| M1 集成骨架 | 六个 active gitlink,另固定 28 个直属和 2 个 Web 子级的 planned 开发提交 | 查看候选 Woodpecker 运行及各组件独立 CI |
|
||||
| M2 标准库切换 | planned,CLI RC.4 提供官方完整 Bundle | [CLI 外部 Bundle](https://git.cflmy.cn/cflmy/marqdo-cli/issues/11) 和 [九组件切换](https://git.cflmy.cn/cflmy/marqdo/issues/2),包括 HTTP、Regex、Archive 迁出与同步删除旧路径 |
|
||||
| M3 跨仓闭环 | 工单、人工候选、同 SHA 门禁 | [跨仓库 CI](https://git.cflmy.cn/cflmy/marqdo/issues/3) 跟踪真实缺陷闭环、候选通知鉴权、去重和影响分析 |
|
||||
| M4 领域接入 | Web 领域 planned:三仓文档与工单就绪;根 catalog 登记 planned domain | W-M0 真实 CLI 风险探测、WEB-01/02 实现、领域 gitlink、根递归校验与冷安装验收;Stdlib 聚合按 STD-01..04 独立推进 |
|
||||
| 后续领域 | 空仓和预期职责 | 逐组件开展最小真实功能、独立 CI、制品与接入 |
|
||||
|
||||
### 标准库切换顺序
|
||||
|
||||
1. CLI 打包器与产品测试接受单一显式外部 Bundle 输入。内核独立编译;制品仍附带一个校验过的标准库。
|
||||
2. 标准库在各组件维护唯一生产源码和自测。组装拒绝冲突、符号链接或测试污染,调用 CLI 权威打包器。std-io 维护 print/打印 的别名元数据。
|
||||
3. HTTP、Regex、Archive 的真实替代和授权回归先行。候选同时移除 CLI 中旧领域宿主服务和旧导入。
|
||||
4. 验证同输入两次组装结果、摘要及路径负例、C1/C2/C3、独立冷安装和真实工具集成后,再切换基础发行。当前状态为 UNVERIFIED。
|
||||
|
||||
## 标准库源码归位迁移(marqdo#9,2026-11-26 M0 冻结)
|
||||
|
||||
本节是标准库迁出的**唯一现行台账**,取代此前按未来目录规划起草的路径表(如 `system/clock.mq.md`、`io/index.mq.md`);旧路径方案会改变公开 `std:` 路径,与“迁移不改语言/库语义”冲突,已作废。详细实施与验收见父仓工单 [marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9),各接收仓子工单在对应仓库 issue #1。
|
||||
|
||||
### 基线与身份(M0)
|
||||
|
||||
| 对象 | 权威身份 |
|
||||
| --- | --- |
|
||||
| 根仓库 | `cflmy/marqdo@484cb10d66db9b92f0527499642ae6abddb3ef29` |
|
||||
| CLI 标准库源 | `cflmy/marqdo-cli@452e9a32bd9e40dba427d4180691c58bab74449e`(RC.4 发行组合;`stdlib/` 自 `4bbefc9` 起未变) |
|
||||
| 迁移前 Bundle | `marqdo-stdlib@0.1.0`,tree digest `sha256:5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713`(含 `tests/`) |
|
||||
| 公开函数台账 | 20 个模块、151 个 H2 函数,由基线 Bundle 上 `marqdo inspect --signature` 生成并记入各接收仓工单 |
|
||||
| CLI 显式 Bundle 输入 | [marqdo-cli#11](https://git.cflmy.cn/cflmy/marqdo-cli/issues/11) Phase A(PR #12)已提供 `--stdlib-dir`/pin 校验;Phase B(删除仓内源树)以本台账根组合验收为前置 |
|
||||
|
||||
### 模块归属与冻结发布路径
|
||||
|
||||
接收仓库负责源码、测试和后续缺陷;根只做组合、锁定和验收。`modules/` 镜像 Bundle 根相对路径,只收模块不收 `tests/`;官方 manifest 由根唯一生产者生成。
|
||||
|
||||
| 原 CLI 路径(相对 `stdlib/`) | 接收仓 / 工单 | 冻结发布路径(Bundle 根相对) | 公开函数 |
|
||||
| --- | --- | --- | --- |
|
||||
| `clock.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `clock.mq.md` | 1 |
|
||||
| `datetime.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `datetime.mq.md` | 14 |
|
||||
| `env.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `env.mq.md` | 2 |
|
||||
| `process.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `process.mq.md` | 1 |
|
||||
| `random.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `random.mq.md` | 2 |
|
||||
| `format.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `format.mq.md` | 8 |
|
||||
| `io.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `io.mq.md` | 5 |
|
||||
| `io/console.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `io/console.mq.md` | 4 |
|
||||
| `io/stream.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `io/stream.mq.md` | 3 |
|
||||
| `data/json.mq.md` | [std-data#1](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/1) | `data/json.mq.md` | 22 |
|
||||
| `data/csv.mq.md` | [std-data#1](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/1) | `data/csv.mq.md` | 7 |
|
||||
| `data/table.mq.md` | [std-collections#1](https://git.cflmy.cn/cflmy/marqdo-std-collections/issues/1) / [std-data#1](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/1) | `collections/table.mq.md`(8 个值操作)/ `data/table.mq.md`(4 个序列化) | 12 |
|
||||
| `fs/file.mq.md` | [std-fs#1](https://git.cflmy.cn/cflmy/marqdo-std-fs/issues/1) | `fs/file.mq.md` | 14 |
|
||||
| `path.mq.md` | [std-fs#1](https://git.cflmy.cn/cflmy/marqdo-std-fs/issues/1) | `path.mq.md` | 8 |
|
||||
| `text.mq.md` | [std-text#1](https://git.cflmy.cn/cflmy/marqdo-std-text/issues/1) | `text.mq.md`(`utf8编码` 薄封装) | 1 |
|
||||
| `text/utf8.mq.md` | [std-text#1](https://git.cflmy.cn/cflmy/marqdo-std-text/issues/1) | `text/utf8.mq.md`(唯一编解码实现) | 10 |
|
||||
| `net/http.mq.md` | [ext-http#1](https://git.cflmy.cn/cflmy/marqdo-ext-http/issues/1) | 显式 Package 入口 `index.mq.md`,**不进入默认 Bundle**,不再是 `std:` | 11 |
|
||||
| `regex.mq.md` | [ext-regex#1](https://git.cflmy.cn/cflmy/marqdo-ext-regex/issues/1) | 显式 Package 入口 `index.mq.md`,**不进入默认 Bundle**,不再是 `std:` | 22 |
|
||||
| `compress.mq.md` | [ext-archive#1](https://git.cflmy.cn/cflmy/marqdo-ext-archive/issues/1) | 显式 Package 入口 `index.mq.md`,**不进入默认 Bundle**,不再是 `std:` | 2 |
|
||||
| `demo.mq.md` | 不设接收仓;根 Bundle 组合 fixture | 不作为公开安装模块 | 2 |
|
||||
|
||||
`std-core`、`std-encoding`、`std-net` 没有与之对应的旧模块:本轮不发空工单、不激活、不要求补齐未来规划;若已实现模块被本期 Bundle 实际依赖,再按真实依赖补充工单。
|
||||
|
||||
### 原测试断言归属
|
||||
|
||||
每项必须在新归属留下真实执行证据;跨模块断言归根 Bundle 组合测试。
|
||||
|
||||
| 原 `stdlib/tests/` 文件 | 接收仓 | 断言载体 |
|
||||
| --- | --- | --- |
|
||||
| `clock.mq.md`、`datetime.mq.md`、`env.mq.md`、`process.mq.md`、`random.mq.md` | std-system | 组件 case,覆盖原 Rust 断言 |
|
||||
| `console.mq.md`、`format.mq.md`、`io.mq.md`、`stream.mq.md` | std-io | 组件 case + resource 端点事件检查 |
|
||||
| `csv.mq.md`、`json.mq.md` | std-data | 组件 case,覆盖原 Rust 断言 |
|
||||
| `table.mq.md` | std-collections(值操作)+ std-data(GFM)+ 根组合 | 切分后的组件 case 与根组合用例 |
|
||||
| `fs.mq.md`、`path.mq.md` | std-fs | 组件 case,覆盖原 Rust 断言 |
|
||||
| `text.mq.md`、`utf8.mq.md` | std-text | 组件 case,覆盖原 Rust 断言 |
|
||||
| `http.mq.md` | ext-http | 领域回归(基线仅运行级覆盖,需补真实断言) |
|
||||
| `regex.mq.md` | ext-regex | 领域回归,覆盖原 Rust 断言 |
|
||||
| `compress.mq.md` | ext-archive | 领域回归,覆盖原 Rust 断言 |
|
||||
| `demo.mq.md` | 根 Bundle 组合测试 | 组合运行证据 |
|
||||
|
||||
### 决策与取舍
|
||||
|
||||
1. **冻结路径**:以 Bundle 根相对路径为公开身份,迁移不改 `std:` 导入路径;被旧台账规划改名(如 `system/clock.mq.md`、`io/index.mq.md`)的条目按本表冻结。
|
||||
2. **测试不随发行**:`tests/` 迁入组件仓并留在仓库外,默认 Bundle 只含模块;因此 Bundle 内容必然变化,版本与 digest 由 MIG-BUNDLE 唯一生产者显式更新,摘要算法不变。
|
||||
3. **Table 切分**:值操作以 `std:collections/table` 为唯一权威,GFM 序列化以 `std:data/table` 为唯一权威;不保留旧 `std:data/table` 的值操作兼容转发,已知消费者在同一候选内更新。
|
||||
4. **Text 去重**:UTF-8 编解码唯一实现在 `text/utf8.mq.md`,`text.mq.md#utf8编码` 为保留公开名称的薄封装。
|
||||
5. **IO 别名**:`io.mq.md` 保持官方 `print`/`打印` 的别名目标 `写值`,签名与 effects 不变;别名元数据仍由 Bundle 生产者生成。
|
||||
6. **三个领域模块**:HTTP/Regex/Archive 迁入既有扩展仓,按现行 Package 布局以 `index.mq.md` 为唯一公开入口(消费者经 `@alias` 显式依赖),退出默认 Bundle,不保留隐藏的 `std:` fallback;HTTP 的 bundle 内相对 import 改为公开 `std:text/utf8`。CLI 现有 `regex.*`/`compress.*` 宿主请求是历史例外,本轮不删除也不新增同类请求,彻底消除另开工单。
|
||||
7. **`demo.mq.md`**:不作为公开库模块,转为根 Bundle 组合 fixture,避免为了放置文件创建无独立责任的新仓库。
|
||||
8. **staging 不是发行**:迁移期为了隔离测试,允许用基线 Bundle 覆盖组件模块并重算 digest 的 staging 组合;它不是官方发布源,最终只有根唯一生产路径。
|
||||
9. **CLI 侧最小修改**:Phase A 显式制品输入已落地;Phase B 删除仓内官方源树只在组件替代与根组合验收通过后执行,不同时进行核心重构。
|
||||
10. **未创建的新仓**:不为缺失模块创建同名替代仓;`marqdo-stdlib` 聚合仓仍未建立,聚合治理按原独立计划推进,不阻塞本次源码归位。
|
||||
|
||||
### 迁移状态
|
||||
|
||||
| 项 | 状态 | 证据 |
|
||||
| --- | --- | --- |
|
||||
| M0 盘点与派单 | 完成 | 本节、9 个接收仓 issue #1、[marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9) 评论 |
|
||||
| 组件接收(源码+断言) | 候选已推送(6 个 std 仓,同候选配对) | [std-text PR #2](https://git.cflmy.cn/cflmy/marqdo-std-text/pulls/2)、[std-system PR #2](https://git.cflmy.cn/cflmy/marqdo-std-system/pulls/2)、[std-io PR #2](https://git.cflmy.cn/cflmy/marqdo-std-io/pulls/2)、[std-fs PR #2](https://git.cflmy.cn/cflmy/marqdo-std-fs/pulls/2)、[std-data PR #2](https://git.cflmy.cn/cflmy/marqdo-std-data/pulls/2)、[std-collections PR #2](https://git.cflmy.cn/cflmy/marqdo-std-collections/pulls/2) |
|
||||
| 领域模块(http/regex/archive) | 候选已合并为显式 Package | [ext-http PR #2](https://git.cflmy.cn/cflmy/marqdo-ext-http/pulls/2)、[ext-regex PR #2](https://git.cflmy.cn/cflmy/marqdo-ext-regex/pulls/2)、[ext-archive PR #2](https://git.cflmy.cn/cflmy/marqdo-ext-archive/pulls/2) |
|
||||
| Bundle 唯一生产者 | 已实现,M2 候选真实构建两次逐字节一致 | `scripts/build-stdlib.py`、`scripts/stdlib-bundle.json`、`tests/integration/test_build_stdlib.py` |
|
||||
| 组合验收入口 | M2 候选 PASS(组件 entry + 跨仓组合 + 负例 + 相邻离线安装 + CLI 确定性打包) | `scripts/acceptance-stdlib.py`、[M2 候选证据](evidence/2026-11-26-stdlib-m2-candidate.md)、[根 PR #11](https://git.cflmy.cn/cflmy/marqdo/pulls/11) |
|
||||
| CLI 旧源树删除 | 候选完成:CLI 仓已无 `stdlib/` 源树、无编译期 fallback,pin 指向生态 Bundle | [marqdo-cli#11](https://git.cflmy.cn/cflmy/marqdo-cli/issues/11)、[CLI PR #17](https://git.cflmy.cn/cflmy/marqdo-cli/pulls/17)、[Phase B 证据](https://git.cflmy.cn/cflmy/marqdo-cli/src/branch/migration/cli-stdlib-phase-b/docs/evidence/2026-11-27-issue-11-phase-b.md) |
|
||||
| 统一 CLI/Worker/Bundle 制品输入(ECO-02 核心) | 已落地:integration.sh 由同一根候选派生全部输入,不再使用 View 冻结制品 | 根 `scripts/integration.sh`、[marqdo#7](https://git.cflmy.cn/cflmy/marqdo/issues/7) |
|
||||
| 根组合与切换 | **已晋升**:`main` = `f4e292e`,固定 CLI Phase B `deadf6e` 与六个 std/三个 ext 组件;根生态 CI(pipeline 38)PASS | [M3 证据](evidence/2026-11-27-stdlib-m3-candidate.md)、[根 PR #12](https://git.cflmy.cn/cflmy/marqdo/pulls/12) |
|
||||
| M4 发行级验收 | 离线冷安装 PASS(`ubuntu:24.04 --network none`,归档 `sha256:377d2787...`);多平台不在本线支持矩阵 | [M3 证据的晋升章节](evidence/2026-11-27-stdlib-m3-candidate.md#晋升与-m4-验收) |
|
||||
|
||||
## v2 功能历史索引
|
||||
|
||||
按表中的归属逐项拆分工单,记录来源路径、目标接口、正负例、状态和真实测试提交。
|
||||
|
||||
| 旧版 lib 模块 | 目标 | 迁移决策 / 主要缺口 |
|
||||
|---|---|---|
|
||||
| archive | archive | ZIP/TAR 等安全归档;现有 gzip 迁移,测试路径穿越 |
|
||||
| browser | browser | 31 个 H2 所涉 DOM、存储、事件、fetch、WS、下载;不复制旧 WASM runtime |
|
||||
| bytes | std-text / std-encoding | 字节值、slice、UTF-8 归 Text,base64 归 Encoding,单一 byte 表示 |
|
||||
| cli | std-system | 应用参数 parse,非 CLI 自身 flag parser |
|
||||
| csv | std-data | 已有 parse/format;补非法输入与多行测试 |
|
||||
| datetime | std-system / datetime | UTC 基础已有;时区、DST 和高级日历明确拆分 |
|
||||
| document | document | sections、tables、links、code blocks、replace;通过受支持静态事实与显式文件编辑 |
|
||||
| encoding | std-encoding | Base64/Base32/Hex 编解码缺失 |
|
||||
| foreign | CLI 现有 Foreign / 独立可选会话扩展(待 ADR) | one-shot run/call 已有;不恢复 set_cmd/register 等隐式动态机制;session/replay 需真实设计 |
|
||||
| fs | std-fs / document / engineering | 40 个 H2 涵盖文件操作;新版14个 H2;二进制、递归、原子、临时、读写组合;文本 patch/工程 sync 归相应扩展 |
|
||||
| hash | crypto | SHA/HMAC 等,密码学不进入内核 |
|
||||
| html | web(合同见 WEB-DESIGN) | HTML escape/unescape 属渲染安全细节,按 WEB-DESIGN 与 Preview 安全合同处理;不恢复旧页面/模板插件模型 |
|
||||
| json | std-data | parse/stringify 已有;get/keys/set 等可复用 collections;严格 Result |
|
||||
| log | std-system | 结构化、level、输出门面,不引入服务框架 |
|
||||
| math | std-core / math | abs/min/max/clamp 基础归 Core;数值、超越、公式、CAS、绘图归 Math;随机归 System |
|
||||
| net | std-net / http / ai / document | TCP/TLS 基础归 Net;HTTP/SSE/cookie/multipart/download 归 HTTP;OpenAI 特定 SSE 归 AI;Markdown 解析归 Document 或公开静态事实 |
|
||||
| path | std-fs | join/normalize 等已有;relative/with_extension 等补齐 |
|
||||
| plugin | CLI 现行扩展选择机制 | 不迁移 load/unload 自动加载;使用显式 descriptors、lock、grant |
|
||||
| re | regex | 查找/替换/分割/捕获和现有纯子集、成熟后端,取消宿主 convenience 重复 |
|
||||
| result | std-core | ok/error/value_or,统一现行可恢复错误约定 |
|
||||
| secrets | std-system / crypto | token 生成归 System,密钥/密码学安全操作归 Crypto;不泄漏 secret |
|
||||
| stats | math | mean/median/stdev;定义样本与总体、空集合、精度 |
|
||||
| subtask | CLI Structured Tasks(待开发) / std-system | spawn/join/cancel 等先验证通用语义;库只薄封装,不移植旧 scheduler |
|
||||
| sys | std-system / CLI 公共事实 | env/args/process/clock;旧 stream_publish 和 meta 由现行 Observation/Analysis 或真正应用输出处理;不恢复隐式环境写入 |
|
||||
| table | std-collections / std-data | 60 个 H2 入口(List/Map/Table 混合);值操作归 Collections,GFM/数据格式归 Data |
|
||||
| text | std-text | trim/split/join、contains/replace、大小写、repeat/pad 等缺口 |
|
||||
| time | std-system | now/UTC parse 已部分有;sleep 仅在受控原语可用后实现 |
|
||||
| toml | std-data | parse/stringify/try_parse,实际支持标准及错误边界 |
|
||||
| url | http | URL parse/query/percent 与同协议归属,std-net 不重复 |
|
||||
| uuid | std-system | v4 使用 OS entropy;检查版本/variant |
|
||||
| writeback | document / engineering | 显式有界编辑、来源摘要及冲突检查;不恢复隐式自修改/自动 oracle writeback |
|
||||
| lint/narrative | lint Tool | 静态诊断与显式修复,不进 CLI runtime |
|
||||
|
||||
### 领域与插件
|
||||
|
||||
| 旧目录 | 目标及处理 |
|
||||
|---|---|
|
||||
| `ext/ai` + `plugins/llm` / `plugins/agent` | AI 模型协议、MCP 独立迁移;agent 97 个 H2 涉及 workflow/memory/工具/恢复等,按真实通用能力拆分,不整体复制。qdagent 应用管理其自己的最小工作流、记忆、意图和 SKILL,不作为通用标准库。知识检索、证明分别由对应 Tool;sandbox 用 CLI 的实际保证,不伪造 OS 隔离。 |
|
||||
| `ext/linalg` + `plugins/linalg` | Linalg;迁移数值算法、复数及矩阵符号知识;重新适配 ABI,减少重复。 |
|
||||
| `ext/quantum` + `plugins/quantum` | Quantum;gate/state/circuit/simulate/density/viz,移除与 Linalg 重复的实现或建立经测试的后端共享边界。 |
|
||||
| `ext/net` | HTTP、WebSocket、URL,低层 TCP/TLS 归 Std Net。 |
|
||||
| `ext/data` | Database/Cache/Storage;form/admin/api/view 的 Web 部分归 Web,数据验证及查询归唯一相应库。旧 Web Go plugin 的 DB、storage、cache 子模块分别迁移。 |
|
||||
| `ext/security` | Security + Crypto;旧 Go plugin auth/OIDC/RBAC/tenant/password 按归属拆分,不混入 Host capability。 |
|
||||
| `ext/web` + `plugins/web` | 拆为 Web 设计原型领域(唯一合同见 marqdo-ext-web `docs/WEB-DESIGN.md`:设计文档解释、递归组件、有限场景、离线预览与 handoff)与 HTTP/WebSocket/Browser/Database/Security 各自独立组件;删除 monolithic Go plugin 调度与旧页面模型,不恢复旧 Web Artifact 兼容层。 |
|
||||
| `ext/engineering` + `plugins/engineering` | Engineering;Git 操作、文件、archive 分配给已有权威库,避免重复平台操作。 |
|
||||
| `crates/marqdo-wasm`、旧 browser examples | Browser 组件参考;语言核心可移植性需要 CLI 工单,而非复制旧执行器。 |
|
||||
| 旧 `src/knowledge`/proof/view/lint/对应历史 CI 与 examples | 独立 Tool,只迁移所需知识、算法和 fixture;当前公共 Analysis/Observation 优先;新旧协议不并存。 |
|
||||
@@ -1,76 +0,0 @@
|
||||
# Marqdo 各仓库任务
|
||||
|
||||
按仓库领取任务。标为 **大改** 的条目可涉及模块拆分、实现重写或发布切换。责任仓库应先限定本轮交付范围,涉及公共接口时与实际消费者一起验收。
|
||||
|
||||
生态治理采用“根 → 领域聚合 → 功能组件”最多两级 Gitlink:功能仓库实现与修复、领域聚合仓库维护合同与组合验收、主仓库固定 gitlink、治理与发行。`planned` 组件可以挂载真实开发提交,实际入口随验收登记。当前没有 active 领域;Web 领域为 planned(聚合仓 `marqdo-ext-web`,子组件 `marqdo-web-design`/`marqdo-web-preview` 在其 catalog 登记)。先推进 CLI 外部 Bundle、九个标准库,以及 HTTP、Regex、Archive 的迁出;这些改动在同一候选组合中验证后切换基础发行。官网和 VS Code 可独立推进。[迁移台账](MIGRATION.md) · [开发流程](DEVELOPMENT.md)
|
||||
|
||||
## 集成和语言
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo` | 固定已验收的组件组合与领域 gitlink,完成跨仓库工单闭环、CI 和生态发行验证。推进递归治理校验(domain 角色与全局依赖 DAG)、声明驱动集成计划、统一 CLI 制品输入与递归影响分析;保留现有 conformance/View/Knowledge/Prove/Lint 真实门禁。 |
|
||||
| `marqdo-cli` | **大改**。拆分内核构建和基础发行装配,接受显式外部标准库 Bundle。完成领域能力迁出后,移除旧标准库入口和被替代的专用宿主实现。 |
|
||||
| `marqdo-extension-conformance` | 更新真实 CLI 的公共契约测试,覆盖 Bundle 切换、五类扩展机制及其权限边界。 |
|
||||
|
||||
## 领域聚合(planned)
|
||||
|
||||
领域聚合仓库只做治理、唯一合同、示例、跨组件验收与交付协调,不含生产实现。激活前保持 planned,子组件在其自身 `components.toml` 登记,根 catalog 不重复登记。
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-ext-web` | Web 领域聚合:维护唯一作者合同 `docs/WEB-DESIGN.md`、§8 组合示例与领域 CI;验证真实 Analysis 风险(WEB-00),协调设计合同变更与 Design/Preview 配对候选;在子组件通过 WEB-01..04 后以领域 gitlink 接入根(WEB-05)。 |
|
||||
| `marqdo-web-design` | WEB-01:消费真实 CLI Analysis 3,解释精确组件引用、递归布局、有限场景与依赖,输出稳定诊断、组件图和源身份;WEB-03:handoff、单组件切片与漂移标识。独立 Rust library,禁止复制 parser/启动服务。 |
|
||||
| `marqdo-web-preview` | WEB-02:通用离线预览渲染器与有限状态交互、响应式、安全负例、Tool 打包;作为唯一 `web` 命令入口消费 Design 公开 API,禁止任务专用 JS、第二套解析或生产服务器。 |
|
||||
|
||||
## 工具和产品
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-knowledge` | 基于公开 Analysis 完善可复现的知识编译、索引和检索,验证独立发行。 |
|
||||
| `marqdo-prove` | 完善证明依赖、Lean 证书生成和独立重放,清楚展示各项证明的核验状态。 |
|
||||
| `marqdo-view` | 维护文档阅读、显式运行、Observation 和静态导出,验证与现行 CLI 及官网构建的组合。 |
|
||||
| `marqdo-lint` | 扩展静态规则和诊断定位,为可修复规则提供显式修复。 |
|
||||
| `marqdo-site` | **大改**。用现行 CLI 和 View 重建官网与入门内容,验证新站和旧链接后切换托管。 |
|
||||
| `marqdo-vscode` | **大改**。按现行 CLI 重做诊断和运行适配,先完成高亮、静态诊断、显式运行和可安装的 VSIX。 |
|
||||
|
||||
## 标准库
|
||||
|
||||
每个仓库交付可独立测试的模块,共同组成默认 Bundle。标准库源码归位已完成并晋升:六个交付源码的 `std-*` 在根 catalog 为 active,`std-core/encoding/net` 保持 planned 且不入 Bundle;CLI 已无内置标准库源树,唯一 Bundle 由根 `scripts/build-stdlib.py` 从固定 gitlink 生成,组合验收为 `scripts/acceptance-stdlib.py`。迁移基线、模块/函数与断言台账、冻结发布路径见 [迁移台账](MIGRATION.md) 的“标准库源码归位迁移”一节。`marqdo-stdlib` 聚合仓库仍未建立;发行级冷安装已通过,后续缺陷回各责任仓。
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-std-core` | 实现共用 Result 和基础数值操作。 |
|
||||
| `marqdo-std-collections` | 实现 List、Map 和 Table 的通用集合操作,从数据格式处理中拆出表格算法。 |
|
||||
| `marqdo-std-text` | 统一 Unicode 文本、字节值切片和 UTF-8 编解码。 |
|
||||
| `marqdo-std-encoding` | 提供 Base64、Base32 和 Hex,并定义非法输入的行为。 |
|
||||
| `marqdo-std-data` | 迁入 JSON、CSV 和表格格式转换,补齐 TOML 与 GFM。 |
|
||||
| `marqdo-std-io` | 迁入 Console、Stream 和格式化,负责官方 `print` 与 `打印` 别名。 |
|
||||
| `marqdo-std-fs` | 迁入文件、路径和目录操作,核验读写边界。 |
|
||||
| `marqdo-std-system` | 迁入时钟、UTC、环境、进程和随机能力。 |
|
||||
| `marqdo-std-net` | 提供有界 TCP、UDP、TLS 和字节流,供上层协议复用。 |
|
||||
|
||||
## 扩展
|
||||
|
||||
每个仓库先完成一个可安装、可验证的用例。历史实现可用于迁移取证,公开接口按现行契约验收。
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-ext-math` | 建立数值算法、统计、符号数学和绘图能力,先交付可验证的数值用例。 |
|
||||
| `marqdo-ext-linalg` | 迁移复数、矩阵和分解,向量子组件提供可复用的线性代数接口。 |
|
||||
| `marqdo-ext-quantum` | 迁移量子电路、态向量、采样与模拟,验证代表性电路结果。 |
|
||||
| `marqdo-ext-http` | **大改**。把现有 HTTP 迁为基于 std-net 的独立包,覆盖 URL、消息编解码、请求生命周期和 SSE。 |
|
||||
| `marqdo-ext-websocket` | 交付基于 HTTP 与网络流的 WebSocket 握手、帧和连接生命周期。 |
|
||||
| `marqdo-ext-ai` | **大改**。从旧 AI 实现拆出模型协议、流式输出和工具调用数据。 |
|
||||
| `marqdo-ext-mcp` | 交付 MCP 传输、能力发现和受控工具调用。 |
|
||||
| `marqdo-ext-crypto` | 封装成熟密码学实现,先交付一种带标准测试向量的能力。 |
|
||||
| `marqdo-ext-database` | 交付一个支持参数绑定和事务的数据库驱动。 |
|
||||
| `marqdo-ext-storage` | 定义本地与对象存储接口,先验证一套读写和错误处理流程。 |
|
||||
| `marqdo-ext-cache` | 交付带 TTL 和失效行为的缓存。 |
|
||||
| `marqdo-ext-security` | 交付应用身份、会话与授权,复用加密扩展。 |
|
||||
| `marqdo-ext-web` | 已改为 Web 领域聚合仓库,任务见「领域聚合」小节;不再作为 HTTP 页面/路由渲染实现。 |
|
||||
| `marqdo-ext-browser` | **大改**。按现行运行时边界适配浏览器宿主、WASM、DOM 和事件。 |
|
||||
| `marqdo-ext-document` | 交付 Markdown 结构查询与显式编辑接口。 |
|
||||
| `marqdo-ext-archive` | 实现归档与安全解包,为 CLI 移除旧压缩入口提供可验证的替代。 |
|
||||
| `marqdo-ext-engineering` | 拆分工程操作、文件补丁和产物处理,先交付一个独立工程用例。 |
|
||||
| `marqdo-ext-regex` | 提供匹配、捕获、扫描与替换,为 CLI 移除旧正则入口提供可验证的替代。 |
|
||||
| `marqdo-ext-datetime` | 交付 IANA 时区、夏令时和高级日历能力,与标准库 UTC 接口对接。 |
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,7 +0,0 @@
|
||||
# 架构决策记录
|
||||
|
||||
按时间顺序保存影响生态边界、公共合同或发行方式的决策。现行规则以 `docs/ARCHITECTURE.md`、`docs/DEVELOPMENT.md`、`components.toml` 与各责任仓库的合同文档为准;ADR 是决策历史,不是第二套现行规范。
|
||||
|
||||
| ADR | 状态 | 主题 |
|
||||
| --- | --- | --- |
|
||||
| [0001](0001-hierarchical-ecosystem-and-web-domain.md) | 已采纳(实施记录) | 分层生态治理(根→领域→功能)与 Web 原型设计领域合同 |
|
||||
@@ -1,72 +0,0 @@
|
||||
# 标准库源码归位 M2 候选证据(2026-11-26)
|
||||
|
||||
父仓工单:[cflmy/marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9)。本文件记录 **M2 候选组合**的真实执行结果,是候选证据,不是已发布声明。根主分支仍保持迁移前组合(`484cb10`);本候选只有在 CLI Phase A 与六个接收仓 PR 合并、且完整生态门禁通过后才可晋升。
|
||||
|
||||
## 候选身份
|
||||
|
||||
| 对象 | 身份 |
|
||||
| --- | --- |
|
||||
| 根候选分支 | `migration/stdlib-m2-candidate`(本文档提交前树 `8fa728b302fa29caf8268a758eb4b0e90431d780`) |
|
||||
| 根主分支基线 | `484cb10d66db9b92f0527499642ae6abddb3ef29`(未改动) |
|
||||
| CLI gitlink(未变) | `cflmy/marqdo-cli@452e9a32bd9e40dba427d4180691c58bab74449e`(RC.4 组合) |
|
||||
| CLI Phase A 候选(仅用于打包/验证,PR #12) | `cflmy/marqdo-cli@f8b82d414328d92b31865fed05e68223f7bee917` |
|
||||
| std-text | `cflmy/marqdo-std-text@c2a7d327e5d1914db8952562614707c112a07da1`(PR #2) |
|
||||
| std-system | `cflmy/marqdo-std-system@053ddb0e59dc016b9c7833f115d14fa04e721d48`(PR #2) |
|
||||
| std-io | `cflmy/marqdo-std-io@e18b0b1b40fcc6adcb42b5ab9fe1c9c04e9b8263`(PR #2) |
|
||||
| std-fs | `cflmy/marqdo-std-fs@63bceae58736f13770c7eead02535726d08c19d0`(PR #2) |
|
||||
| std-data | `cflmy/marqdo-std-data@848af7a357ceda2cfc20721b93406cf4be705889`(PR #2) |
|
||||
| std-collections | `cflmy/marqdo-std-collections@490765226866ac74b7365471c202e7638187bff8`(PR #2) |
|
||||
| ext-http(显式 Package) | `cflmy/marqdo-ext-http@368b33d241`(PR #2,合并后精确 SHA 以根 gitlink 为准) |
|
||||
| ext-regex(显式 Package) | `cflmy/marqdo-ext-regex@6e7e633798`(PR #2) |
|
||||
| ext-archive(显式 Package) | `cflmy/marqdo-ext-archive@aba6b60934`(PR #2) |
|
||||
|
||||
`std-core`、`std-encoding`、`std-net` 保持 `planned`,不加入 Bundle。HTTP/Regex/Archive 已迁为显式 Package(`index.mq.md` + `marqdo.yaml`,消费者经 `@alias` 导入),不进入默认 Bundle;其源码候选已合并到各自仓库 main,根候选固定对应提交并执行显式 Package 消费门禁(`kind = "explicit-package"`)。
|
||||
|
||||
## 唯一 Bundle 制品
|
||||
|
||||
`scripts/build-stdlib.py` 从上述根 gitlink 组合,两次干净构建逐字节一致:
|
||||
|
||||
| 字段 | 值 |
|
||||
| --- | --- |
|
||||
| name / version | `marqdo-stdlib` / `0.2.0`(内容变化显式升版本;摘要算法不变) |
|
||||
| tree digest | `sha256:db905508dde89763b9d43b47fc5d52c6a1d5445a91f3c86a550ced43e8aac9d7` |
|
||||
| aliases digest | `sha256:5f513c0fdbb3c1e9829be3c9fa23a2d1e89cb8510073fb5eb1e8e2f5265a83bb`(与迁移前一致) |
|
||||
| 模块数 | 17(仅模块;`tests/`、`demo.mq.md`、`net/http`、`regex`、`compress` 均不在默认 Bundle) |
|
||||
| 打包归档 | `marqdo-stdlib-0.2.0.tar.gz`,`sha256:212cca32f10ecfa0cdedfa976f7726db5e01cdb0e664a41ae26d4b34a8fd7048`(CLI Phase A `tools/pack-stdlib.py` 两次输出逐字节一致) |
|
||||
|
||||
## 门禁结果
|
||||
|
||||
| 门禁 | 命令 | 结果 |
|
||||
| --- | --- | --- |
|
||||
| 根布局 | `python3 scripts/check-layout.py` | PASS |
|
||||
| 递归布局 | `python3 scripts/check-layout.py --checkouts` | PASS(33 个固定子树;6 个 active stdlib entry 存在且工作区干净) |
|
||||
| 根集成测试 | `python3 -m unittest discover -s tests/integration` | Ran 56 tests,OK(含 9 个 Bundle 生产者契约测试) |
|
||||
| 组件独立验收 | `MARQDO_BIN=<RC.4 由 452e9a3 构建> MARQDO_STDLIB_DIR=<新 Bundle> scripts/test.sh`(各仓) | 6/6 PASS,共 17 个 case(collections 1、text 2、data 3、io 4、fs 2、system 5) |
|
||||
| 跨仓组合 | `scripts/acceptance-stdlib.py --cli <CLI> --bundle <新 Bundle>` | PASS:官方 `print`/`打印` 别名、Table 值操作+GFM 跨模块、默认 Bundle smoke |
|
||||
| Table 等价性 | 组合 fixture 终值与迁移前原 `stdlib/tests/table.mq.md` 终值 | 逐字节一致 |
|
||||
| 显式 Package 消费 | `scripts/acceptance-stdlib.py` 内 http/regex/archive 各自 `scripts/test.sh`(临时消费者工程 + `marqdo lock` + `@alias` 导入) | PASS(原领域测试终值与迁移前基线一致) |
|
||||
| 失败负例 | 缺显式 Bundle、篡改模块摘要 | 均按预期失败(exit 1),不静默回退 |
|
||||
| 相邻安装离线运行 | 把新 Bundle 放到 CLI 二进制旁 `stdlib/`,不设 `MARQDO_STDLIB_DIR` | PASS(默认离线安装路径可用) |
|
||||
| CLI 打包 | Phase A `pack-stdlib.py --stdlib-dir <新 Bundle>` ×2 + 篡改输入 | 确定性 PASS;篡改拒绝 |
|
||||
|
||||
CLI 身份(sha256):由 `452e9a3` 构建的 RC.4 二进制 `sha256:0377b855...`;Phase A 合并 master(`f8b82d4`)二进制 `sha256:6ede3b9e...`。两者对同一 Bundle 的组件与组合门禁结果一致。
|
||||
|
||||
## 未验证 / 待办
|
||||
|
||||
- 完整 `scripts/integration.sh` 的既有消费者门禁(Conformance/View/Knowledge/Prove/Lint)本轮**未执行**:该流程仍取冻结 RC.4 制品,本次未替换为统一制品输入(ECO-02,marqdo#7);不能把本次 PASS 当作生态发行验收。
|
||||
- CLI Phase B(删除仓内官方标准库源树、pin 切换)未做,等待 CLI PR #12 合并与本候选组件 PR 合并。
|
||||
- HTTP/Regex/Archive 已成为显式 Package 且组件内测试通过;本候选的根组合门禁只验证了独立 Package 行为,尚未验证真实应用项目的 `git` 依赖锁定/同步与发布分发,也尚未从默认 Bundle 删除后验证既有 `std:` 用户的迁移提示(按合同不保留 fallback)。
|
||||
- 未做完整产品归档冷安装(新 Bundle + 新 CLI 发行归档)与多平台证据;Windows/macOS 未验证。
|
||||
- 根主分支未改动,回退方式为放弃本候选分支,迁移前组合 `484cb10` 仍可检出。
|
||||
|
||||
## 复现
|
||||
|
||||
```sh
|
||||
git checkout migration/stdlib-m2-candidate
|
||||
git submodule update --init --recursive
|
||||
python3 scripts/check-layout.py --checkouts
|
||||
python3 -m unittest discover -s tests/integration
|
||||
python3 scripts/build-stdlib.py --out build/stdlib
|
||||
python3 scripts/acceptance-stdlib.py --cli <verified-marqdo> --work build/accept
|
||||
# 可选:--pack-tool <cli>/tools/pack-stdlib.py(Phase A 之后)
|
||||
```
|
||||
@@ -1,54 +0,0 @@
|
||||
# 标准库源码归位 M3 候选证据(2026-11-27)
|
||||
|
||||
父仓工单:[cflmy/marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9)。
|
||||
本文件记录 **M3 候选组合**(源码所有权切换 + 统一制品输入)的候选证据,不是已完成发行声明。主分支仍保持迁移前组合 `484cb10`,根 PR #12 只有在 CI 通过且 CLI Phase B 合并后才晋升。
|
||||
|
||||
## 候选身份
|
||||
|
||||
| 对象 | 身份 |
|
||||
| --- | --- |
|
||||
| 根候选 | `migration/stdlib-m2-candidate`(CLI Phase B 合并提交 `deadf6e`) |
|
||||
| CLI Phase B 合并 | `cflmy/marqdo-cli@deadf6edeea6dd0f5abf51c47e80204fd851baf0`(PR #17 fast-forward 合并;Phase B 代码提交 `72f57be`,另含 CI 脚本修复;`stdlib/` 已删除,pin 指向生态 Bundle) |
|
||||
| 生态 Bundle | `marqdo-stdlib@0.2.0`,source `cflmy/marqdo@48189243f7`,tree digest `sha256:db905508...`,aliases digest `sha256:5f513c0f...`(17 模块 + manifest) |
|
||||
| 组件固定 | 六个 std 与三个 ext 的已合并候选 SHA(M2 证据同一组) |
|
||||
| 发行归档(本地候选) | `marqdo-3.0.0-rc.4-x86_64-unknown-linux-gnu.tar.gz`,`sha256:9a926010ffe8e7353ee18b65fc568ced8bbf4b09b7592713f1213e2f3e3d40f9`(CLI `72f57be` + 新 Bundle) |
|
||||
|
||||
## 统一制品输入(ECO-02 核心)
|
||||
|
||||
根 `scripts/integration.sh` 不再读取 View 的冻结 RC.4 脚本;一次候选内派生全部输入:
|
||||
|
||||
1. `scripts/build-stdlib.py --out <work>/stdlib` 由固定组件 gitlink 生成唯一 Bundle;
|
||||
2. 从根固定的 `cli/` 提交构建 CLI 与 Provider Worker;
|
||||
3. `cli/tools/release/package.py --source-sha <cli SHA> --version <workspace version> --stdlib-dir <Bundle>` 生成发行归档与 `RELEASE_INFO.json`;
|
||||
4. `cli/tools/release/smoke.py` 验证归档、`SOURCE_SHA`、stdlib 摘要与语言-only 运行;
|
||||
5. `scripts/acceptance-stdlib.py --cli <installed> --bundle <Bundle>` 跑组件 entry、显式 Package、组合 fixture 与失败负例;
|
||||
6. Conformance、View、Knowledge、Prove、Lint 使用同一安装后二进制与相邻 Bundle。
|
||||
|
||||
## 本地候选验证
|
||||
|
||||
| 门禁 | 命令 | 结果 |
|
||||
| --- | --- | --- |
|
||||
| 根布局 | `python3 scripts/check-layout.py --checkouts` | PASS(含 6 个 active stdlib entry 与 9 个固定组件) |
|
||||
| Bundle | `python3 scripts/build-stdlib.py --out <dir>` | 两次构建一致,digest `sha256:db9055...` |
|
||||
| CLI Phase B | `cargo fmt` / `clippy -D warnings` / `cargo test --workspace`(显式 Bundle) | fmt/clippy PASS;72 个测试二进制 PASS |
|
||||
| CLI 工具测试 | `MARQDO_TEST_STDLIB_BUNDLE=<bundle> python3 -m unittest discover -s tools/ci` | 75 tests OK |
|
||||
| 独立构建 | `python3 tools/ci/independent_build.py` | PASS(无 stdlib 源树、无兄弟 Bundle,语言-only 运行成功,依赖 std 的程序 fail-closed) |
|
||||
| 发行归档 | `package.py --stdlib-dir <Bundle>` + `smoke.py --archive` | PASS(stdlib 0.2.0 摘要校验、缺失 Bundle fail-closed、language-only 运行) |
|
||||
| 验收脚本 | `scripts/acceptance-stdlib.py` 本地 M2 版 | PASS(6 组件 + 3 显式 Package + 4 组合 + 2 负例) |
|
||||
|
||||
## 未验证 / 待办
|
||||
|
||||
- 完整根 CI(`scripts/integration.sh` 含 View/Knowledge/Prove/Lint 消费者)在候选分支执行,结果记录在 PR #12/评论,不以本地部分运行替代。
|
||||
- 根晋升(合并 CLI PR #17 与根 PR #12、climo gitlink 与制品同一候选)属 MIG-RELEASE。
|
||||
- 完整产品归档冷安装(docker `--network none`)、多平台、ext-http loopback 领域测试仍待补;如需标记为发行门禁必须另行执行,不得以本文件冒充 PASS。
|
||||
|
||||
|
||||
## 晋升与 M4 验收(2026-11-27)
|
||||
|
||||
- CLI Phase B [PR #17](https://git.cflmy.cn/cflmy/marqdo-cli/pulls/17) fast-forward 合并,`master` = `deadf6e`(contract/test/independent-build/minimum-rust/build 全绿)。
|
||||
- 根 [PR #12](https://git.cflmy.cn/cflmy/marqdo/pulls/12) fast-forward 合并,`main` = `f4e292e7b09057c77e2a9293b40051be2666c4f8`;根树固定 CLI Phase B 与六个 std、三个 ext 提交,六个 stdlib 组件 active。
|
||||
- 根生态 CI 必须门禁 `ci/woodpecker/pr/eco` PASS([pipeline 38](https://ci.cflmy.cn/repos/6/pipeline/38/1)):一次候选派生 Bundle(`sha256:db9055...`)→ 从 cli gitlink 构建 CLI/Worker → `package.py --stdlib-dir`(归档 `sha256:0827ba4b...`)→ smoke → 根 acceptance(组件 entry、显式 Package、组合、负例)→ Conformance/View/Knowledge/Prove/Lint 全部同一安装后二进制与相邻 Bundle。
|
||||
- 发行级离线冷安装:在本机对同一晋升组合(根 `f4e292e`、CLI `deadf6e`、Bundle `db9055`)重新打包(归档 `sha256:377d2787...`)并执行 `cli/tools/release/cold-install.sh`(`ubuntu:24.04`、`--network none`、非 root 用户):PASS——安装后打印、`check`、示例运行、隐藏 Bundle 时 fail-closed、仅语言程序可运行均符合门禁。
|
||||
- 两个归档 SHA 不同是因为示例插件二进制由本机构建产生,不是同一构建环境的确定性证据;确定性打包证据以 CI 同一环境两次构建为准。发行归档身份以 CI/发布记录为准,本文件只记录晋升组合与冷安装通过。
|
||||
|
||||
仍保留为后续(不阻塞本轮关闭):Windows/macOS 不在本线发行支持矩阵;`marqdo-ext-http` 的 HTTP-over-TCP loopback 领域测试;ECO-02 的递归影响分析自动化。
|
||||
@@ -1,32 +0,0 @@
|
||||
# 领域扩展与领域聚合
|
||||
|
||||
本目录覆盖按需安装的领域能力。功能组件默认 `planned`,通过 Git 子模块固定独立仓库的开发提交,完成验收后晋升;聚合仓库不实现子组件业务,根 catalog 只登记 `kind = "domain"` 的聚合本身,不重复登记其后代路径。
|
||||
|
||||
## 领域聚合(planned)
|
||||
|
||||
| 路径 | 仓库 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `web/` | [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web) | Web 原型设计领域聚合:唯一设计合同、示例、组合验收与交付协调;子组件 [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design)、[marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview) 在领域 `components.toml` 登记 |
|
||||
|
||||
## 独立组件(planned)
|
||||
|
||||
- [marqdo-ext-math](https://git.cflmy.cn/cflmy/marqdo-ext-math) · 数值算法、统计、符号数学及绘图
|
||||
- [marqdo-ext-linalg](https://git.cflmy.cn/cflmy/marqdo-ext-linalg) · 复数、矩阵、分解及数值线性代数
|
||||
- [marqdo-ext-quantum](https://git.cflmy.cn/cflmy/marqdo-ext-quantum) · 量子电路、态向量、采样与模拟
|
||||
- [marqdo-ext-http](https://git.cflmy.cn/cflmy/marqdo-ext-http) · HTTP、URL、SSE 与报文生命周期
|
||||
- [marqdo-ext-websocket](https://git.cflmy.cn/cflmy/marqdo-ext-websocket) · WebSocket 握手、帧与连接语义
|
||||
- [marqdo-ext-ai](https://git.cflmy.cn/cflmy/marqdo-ext-ai) · 模型协议、流式输出与工具调用数据
|
||||
- [marqdo-ext-mcp](https://git.cflmy.cn/cflmy/marqdo-ext-mcp) · MCP 协议、传输、发现和调用
|
||||
- [marqdo-ext-crypto](https://git.cflmy.cn/cflmy/marqdo-ext-crypto) · 成熟密码学实现的封装
|
||||
- [marqdo-ext-database](https://git.cflmy.cn/cflmy/marqdo-ext-database) · SQL 参数绑定、事务和驱动连接
|
||||
- [marqdo-ext-storage](https://git.cflmy.cn/cflmy/marqdo-ext-storage) · 本地和对象存储接口
|
||||
- [marqdo-ext-cache](https://git.cflmy.cn/cflmy/marqdo-ext-cache) · TTL、缓存和失效
|
||||
- [marqdo-ext-security](https://git.cflmy.cn/cflmy/marqdo-ext-security) · 应用身份、会话及权限模型
|
||||
- [marqdo-ext-browser](https://git.cflmy.cn/cflmy/marqdo-ext-browser) · 浏览器宿主、WASM 适配、DOM 和事件
|
||||
- [marqdo-ext-document](https://git.cflmy.cn/cflmy/marqdo-ext-document) · Markdown 结构与显式文档编辑
|
||||
- [marqdo-ext-archive](https://git.cflmy.cn/cflmy/marqdo-ext-archive) · 压缩、安全归档和解包
|
||||
- [marqdo-ext-engineering](https://git.cflmy.cn/cflmy/marqdo-ext-engineering) · 工程操作、文件补丁与产物
|
||||
- [marqdo-ext-regex](https://git.cflmy.cn/cflmy/marqdo-ext-regex) · 正则匹配、捕获、扫描和替换
|
||||
- [marqdo-ext-datetime](https://git.cflmy.cn/cflmy/marqdo-ext-datetime) · IANA 时区、DST 和高级日历
|
||||
|
||||
[组件目录](../components.toml) · [各仓库任务](../docs/REPOSITORY-TASKS.md) · [架构边界](../docs/ARCHITECTURE.md)
|
||||
Submodule extensions/ai deleted from 4d2c3e4f1a.
Submodule extensions/archive deleted from aba6b60934.
Submodule extensions/browser deleted from 35c1a75fd0.
Submodule extensions/cache deleted from 0357907e1d.
Submodule extensions/crypto deleted from 21529b8b25.
Submodule extensions/database deleted from e86a397c8e.
Submodule extensions/datetime deleted from 5e2e2a1b34.
Submodule extensions/document deleted from eb88be346a.
Submodule extensions/engineering deleted from b9f3ddba05.
Submodule extensions/http deleted from 368b33d241.
Submodule extensions/linalg deleted from 773ba9ef2e.
Submodule extensions/math deleted from f7ef25014a.
Submodule extensions/mcp deleted from df477bceec.
Submodule extensions/quantum deleted from 33f4780e9e.
Submodule extensions/regex deleted from 6e7e633798.
Submodule extensions/security deleted from 6939018249.
Submodule extensions/storage deleted from 6a798f099e.
Submodule extensions/web deleted from f70095d60a.
Submodule extensions/websocket deleted from e79f2e78fa.
@@ -1,413 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Accept the stdlib migration candidate with explicit, verified inputs.
|
||||
|
||||
This is the root-layer composition gate: it builds (or accepts) the one Bundle
|
||||
produced by ``scripts/build-stdlib.py`` from the pinned component gitlinks, runs
|
||||
each active stdlib component's own entry point against that Bundle, runs the
|
||||
cross-repository composition fixtures, exercises the negative inputs that must
|
||||
fail closed, and optionally packages the Bundle with the CLI's own packer twice
|
||||
to prove determinism.
|
||||
|
||||
Every input is explicit: a real ``marqdo`` executable (``--cli``) and either a
|
||||
Bundle (``--bundle``) or a checkout that can build one at its pinned gitlinks.
|
||||
Nothing is downloaded and no sibling component is discovered implicitly.
|
||||
|
||||
Usage:
|
||||
|
||||
python3 scripts/acceptance-stdlib.py --cli build/marqdo --work build/accept
|
||||
python3 scripts/acceptance-stdlib.py --cli build/marqdo --work build/accept \
|
||||
--pack-tool /path/to/cli/tools/pack-stdlib.py --evidence build/accept/evidence.json
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
CASES = ROOT / "tests" / "integration" / "composition" / "cases"
|
||||
CASES_SCHEMA = "marqdo.stdlib-test-case"
|
||||
FORBIDDEN = {
|
||||
"net/http.mq.md",
|
||||
"regex.mq.md",
|
||||
"compress.mq.md",
|
||||
"demo.mq.md",
|
||||
"tests",
|
||||
}
|
||||
|
||||
|
||||
class AcceptanceError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def run(command, cwd=None, env=None, input_bytes=b""):
|
||||
result = subprocess.run(
|
||||
command, cwd=cwd, env=env, input=input_bytes, capture_output=True
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def sha256(path: Path) -> str:
|
||||
return "sha256:" + hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def channel_text(events: list[dict], channel: str) -> str:
|
||||
chunks = []
|
||||
for event in events:
|
||||
if event.get("kind") != channel:
|
||||
continue
|
||||
payload = event["payload"]
|
||||
data = base64.b64decode(payload["data_base64"])
|
||||
if len(data) != payload["byte_count"]:
|
||||
raise AcceptanceError(f"{channel} byte_count mismatch")
|
||||
chunks.append(data)
|
||||
return b"".join(chunks).decode("utf-8")
|
||||
|
||||
|
||||
def tree_digest(bundle: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for path in sorted(bundle.rglob("*.mq.md"), key=lambda p: p.relative_to(bundle).as_posix()):
|
||||
digest.update(path.relative_to(bundle).as_posix().encode())
|
||||
digest.update(b"\0")
|
||||
digest.update(path.read_bytes())
|
||||
digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def aliases_digest(aliases: list[dict]) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for alias in sorted(aliases, key=lambda a: (a["target_module"], a["target_function"])):
|
||||
digest.update(alias["target_module"].encode()); digest.update(b"\0")
|
||||
digest.update(alias["target_function"].encode()); digest.update(b"\0")
|
||||
for name in sorted(alias["public_names"]):
|
||||
digest.update(name.encode()); digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def verify_bundle(bundle: Path) -> dict:
|
||||
manifest_path = bundle / "stdlib.json"
|
||||
if not manifest_path.is_file():
|
||||
raise AcceptanceError(f"missing Bundle manifest: {manifest_path}")
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
for field in ("name", "version", "digest", "aliases_digest"):
|
||||
if not isinstance(manifest.get(field), str) or not manifest[field]:
|
||||
raise AcceptanceError(f"manifest has no {field}")
|
||||
computed = tree_digest(bundle)
|
||||
if computed != manifest["digest"]:
|
||||
raise AcceptanceError(
|
||||
f"manifest digest mismatch: {manifest['digest']} != {computed}"
|
||||
)
|
||||
aliases = manifest.get("public_aliases", [])
|
||||
expected_alias = aliases_digest(aliases)
|
||||
if expected_alias != manifest["aliases_digest"]:
|
||||
raise AcceptanceError("aliases digest mismatch")
|
||||
files = sorted(
|
||||
path.relative_to(bundle).as_posix()
|
||||
for path in bundle.rglob("*.mq.md")
|
||||
)
|
||||
for relative in files:
|
||||
parts = relative.split("/")
|
||||
if "tests" in parts or relative in FORBIDDEN:
|
||||
raise AcceptanceError(f"forbidden module in Bundle: {relative}")
|
||||
for alias in aliases:
|
||||
if alias["target_module"] not in files:
|
||||
raise AcceptanceError(
|
||||
f"public alias targets missing module {alias['target_module']}"
|
||||
)
|
||||
if "io.mq.md" not in files:
|
||||
raise AcceptanceError("Bundle lost the io.mq.md alias target")
|
||||
return {
|
||||
"manifest": manifest,
|
||||
"files": files,
|
||||
"tree_digest": computed,
|
||||
}
|
||||
|
||||
|
||||
def run_case(cli: str, bundle: Path, case: dict) -> dict:
|
||||
source = ROOT / "tests" / "integration" / "composition" / case["file"]
|
||||
command = [cli, "run", str(source), *case.get("args", []), "--output", "json"]
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_STDLIB_DIR"] = str(bundle)
|
||||
for key, value in case.get("env", {}).items():
|
||||
env[key] = value.replace("$MARQDO_BIN", cli)
|
||||
result = run(command, cwd=ROOT, env=env, input_bytes=case.get("stdin", "").encode())
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} failed: "
|
||||
f"{result.stderr.decode(errors='replace')}"
|
||||
)
|
||||
report = json.loads(result.stdout)
|
||||
if report.get("run", {}).get("status") != "ok":
|
||||
raise AcceptanceError(f"composition case {case['name']} run status not ok")
|
||||
terminal = report["events"][-1]["payload"]
|
||||
if terminal.get("value") != case["expected_terminal"]:
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} terminal value changed"
|
||||
)
|
||||
stdout = channel_text(report["events"], "stdout.chunk")
|
||||
if stdout != case.get("expected_stdout", ""):
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} stdout changed: {stdout!r}"
|
||||
)
|
||||
lines = stdout.splitlines()
|
||||
for left, right in case.get("stdout_line_pairs", []):
|
||||
if left >= len(lines) or right >= len(lines):
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} has no line pair {left}/{right}"
|
||||
)
|
||||
if lines[left] != lines[right]:
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']}: line {left} differs from line {right}: "
|
||||
f"{lines[left]!r} != {lines[right]!r}"
|
||||
)
|
||||
return {"name": case["name"], "status": "PASS"}
|
||||
|
||||
|
||||
def load_components() -> list[dict]:
|
||||
catalog = tomllib.loads((ROOT / "components.toml").read_text())
|
||||
return [
|
||||
component
|
||||
for component in catalog["component"]
|
||||
if component.get("kind") == "stdlib" and component.get("state") == "active"
|
||||
]
|
||||
|
||||
|
||||
def load_explicit_packages() -> list[dict]:
|
||||
"""Planned extensions that already publish an explicit Package entry.
|
||||
|
||||
A component is gated as an explicit package only when its pinned checkout
|
||||
carries the current package layout (``marqdo.yaml`` + ``index.mq.md`` +
|
||||
``scripts/test.sh``); it is never silently loaded into the default Bundle.
|
||||
"""
|
||||
catalog = tomllib.loads((ROOT / "components.toml").read_text())
|
||||
packages = []
|
||||
for component in catalog["component"]:
|
||||
if component.get("kind") != "extension":
|
||||
continue
|
||||
checkout = ROOT / component["path"]
|
||||
if (checkout / "marqdo.yaml").is_file() and (
|
||||
checkout / "index.mq.md"
|
||||
).is_file() and (checkout / "scripts" / "test.sh").is_file():
|
||||
packages.append(component)
|
||||
return packages
|
||||
|
||||
|
||||
def component_gates(cli: str, bundle: Path) -> list[dict]:
|
||||
results = []
|
||||
for component in load_components():
|
||||
entry = ROOT / component["path"] / component["entry"]
|
||||
if not entry.is_file():
|
||||
raise AcceptanceError(
|
||||
f"active component {component['id']} has no entry {component['entry']}"
|
||||
)
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_BIN"] = cli
|
||||
env["MARQDO_STDLIB_DIR"] = str(bundle)
|
||||
result = run([str(entry)], cwd=entry.parent.parent, env=env)
|
||||
output = (result.stdout + result.stderr).decode(errors="replace").strip()
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
f"component {component['id']} failed entry {component['entry']}:\n{output}"
|
||||
)
|
||||
results.append(
|
||||
{
|
||||
"id": component["id"],
|
||||
"entry": component["entry"],
|
||||
"status": "PASS",
|
||||
"output": output,
|
||||
}
|
||||
)
|
||||
for component in load_explicit_packages():
|
||||
entry = ROOT / component["path"] / "scripts" / "test.sh"
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_BIN"] = cli
|
||||
env["MARQDO_STDLIB_DIR"] = str(bundle)
|
||||
result = run([str(entry)], cwd=ROOT / component["path"], env=env)
|
||||
output = (result.stdout + result.stderr).decode(errors="replace").strip()
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
f"explicit package {component['id']} failed: {output}"
|
||||
)
|
||||
results.append(
|
||||
{
|
||||
"id": component["id"],
|
||||
"entry": "scripts/test.sh",
|
||||
"kind": "explicit-package",
|
||||
"status": "PASS",
|
||||
"output": output,
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def negative_gates(cli: str, bundle: Path, work: Path) -> list[dict]:
|
||||
results = []
|
||||
|
||||
def expect_failure(name, command, env_for_gate):
|
||||
result = run(command, env=env_for_gate)
|
||||
if result.returncode == 0:
|
||||
raise AcceptanceError(f"negative gate {name} unexpectedly passed")
|
||||
results.append(
|
||||
{
|
||||
"name": name,
|
||||
"status": "PASS",
|
||||
"exit": result.returncode,
|
||||
"stderr": result.stderr.decode(errors="replace").strip()[:400],
|
||||
}
|
||||
)
|
||||
|
||||
missing = work / "missing-bundle"
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_STDLIB_DIR"] = str(missing)
|
||||
expect_failure(
|
||||
"missing-explicit-bundle",
|
||||
[cli, "run", str(ROOT / "tests/integration/composition/default-bundle.mq.md")],
|
||||
env,
|
||||
)
|
||||
|
||||
tampered = work / "tampered-bundle"
|
||||
if tampered.exists():
|
||||
shutil.rmtree(tampered)
|
||||
shutil.copytree(bundle, tampered)
|
||||
target = next(iter(sorted(tampered.rglob("*.mq.md"))))
|
||||
target.write_bytes(target.read_bytes() + b"\n")
|
||||
env["MARQDO_STDLIB_DIR"] = str(tampered)
|
||||
expect_failure(
|
||||
"tampered-module-digest",
|
||||
[cli, "run", str(ROOT / "tests/integration/composition/default-bundle.mq.md")],
|
||||
env,
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def packaging_gates(pack_tool: str, bundle: Path, work: Path) -> list[dict]:
|
||||
results = []
|
||||
archives = []
|
||||
for attempt in (1, 2):
|
||||
out_dir = work / f"pack-{attempt}"
|
||||
if out_dir.exists():
|
||||
shutil.rmtree(out_dir)
|
||||
result = run(
|
||||
[
|
||||
sys.executable,
|
||||
pack_tool,
|
||||
"--stdlib-dir",
|
||||
str(bundle),
|
||||
"--out-dir",
|
||||
str(out_dir),
|
||||
]
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
"CLI packer rejected the Bundle: "
|
||||
+ result.stderr.decode(errors="replace")
|
||||
)
|
||||
archives.append(sorted(out_dir.glob("*.tar.gz"))[0])
|
||||
if archives[0].read_bytes() != archives[1].read_bytes():
|
||||
raise AcceptanceError("two packaging runs are not byte-identical")
|
||||
descriptor = json.loads(
|
||||
sorted(archives[0].parent.glob("*.json"))[0].read_text()
|
||||
)
|
||||
results.append(
|
||||
{
|
||||
"status": "PASS",
|
||||
"archive": archives[0].name,
|
||||
"archive_sha256": sha256(archives[0]),
|
||||
"tree_digest": descriptor.get("tree_digest"),
|
||||
"aliases_digest": descriptor.get("aliases_digest"),
|
||||
"deterministic": True,
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cli", required=True)
|
||||
parser.add_argument("--work", required=True)
|
||||
parser.add_argument("--bundle")
|
||||
parser.add_argument("--pack-tool")
|
||||
parser.add_argument("--evidence")
|
||||
parser.add_argument("--root-commit")
|
||||
args = parser.parse_args(argv)
|
||||
cli = str(Path(args.cli).resolve())
|
||||
if not Path(cli).is_file():
|
||||
raise SystemExit(f"acceptance-stdlib: error: no CLI executable at {cli}")
|
||||
work = Path(args.work).resolve()
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
if args.bundle:
|
||||
bundle = Path(args.bundle).resolve()
|
||||
else:
|
||||
bundle = work / "bundle"
|
||||
if bundle.exists():
|
||||
shutil.rmtree(bundle)
|
||||
command = [
|
||||
sys.executable,
|
||||
str(ROOT / "scripts" / "build-stdlib.py"),
|
||||
"--out",
|
||||
str(bundle),
|
||||
]
|
||||
if args.root_commit:
|
||||
command += ["--root-commit", args.root_commit]
|
||||
result = run(command, cwd=ROOT)
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
"Bundle producer failed: "
|
||||
+ result.stderr.decode(errors="replace")
|
||||
)
|
||||
bundle_record = verify_bundle(bundle)
|
||||
version = run([cli, "--version"]).stdout.decode().strip()
|
||||
cases = []
|
||||
for path in sorted(CASES.glob("*.json")):
|
||||
case = json.loads(path.read_text())
|
||||
if case.get("schema") != CASES_SCHEMA:
|
||||
raise AcceptanceError(f"unsupported case schema: {path}")
|
||||
cases.append(run_case(cli, bundle, case))
|
||||
components = component_gates(cli, bundle)
|
||||
negatives = negative_gates(cli, bundle, work)
|
||||
packaging = (
|
||||
packaging_gates(args.pack_tool, bundle, work)
|
||||
if args.pack_tool
|
||||
else []
|
||||
)
|
||||
evidence = {
|
||||
"schema": "marqdo.stdlib-acceptance",
|
||||
"schema_version": 1,
|
||||
"cli": {"path": cli, "version": version, "sha256": sha256(Path(cli))},
|
||||
"root_commit": run(
|
||||
["git", "-C", str(ROOT), "rev-parse", "HEAD"]
|
||||
).stdout.decode().strip(),
|
||||
"bundle": {
|
||||
"name": bundle_record["manifest"]["name"],
|
||||
"version": bundle_record["manifest"]["version"],
|
||||
"tree_digest": bundle_record["tree_digest"],
|
||||
"aliases_digest": bundle_record["manifest"]["aliases_digest"],
|
||||
"files": bundle_record["files"],
|
||||
},
|
||||
"components": components,
|
||||
"composition": cases,
|
||||
"negatives": negatives,
|
||||
"packaging": packaging,
|
||||
"status": "PASS",
|
||||
}
|
||||
except AcceptanceError as error:
|
||||
print(f"acceptance-stdlib: FAIL: {error}", file=sys.stderr)
|
||||
return 1
|
||||
text = json.dumps(evidence, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.evidence:
|
||||
Path(args.evidence).write_text(text)
|
||||
print(text)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
@@ -1,397 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build the one official `marqdo-stdlib` Bundle from pinned component gitlinks.
|
||||
|
||||
The producer owns composition only: it collects the published `modules/` files
|
||||
of every **active** `kind = "stdlib"` component at the exact commit pinned by
|
||||
the root Gitlink, validates the published path set, generates the current
|
||||
`stdlib.json` (tree digest + public aliases digest) and writes a deterministic
|
||||
Bundle directory. Component repositories keep the module sources and tests; the
|
||||
root repository does not copy or edit them. The CLI packages the resulting
|
||||
Bundle with its existing `tools/pack-stdlib.py`.
|
||||
|
||||
Identity rules:
|
||||
|
||||
* release mode (default) reads `components.toml`, the Bundle config and the
|
||||
gitlinks from the ``--root-commit`` tree, never from the working tree;
|
||||
* `--worktree` is a development-only mode that reads each component's
|
||||
``HEAD`` and requires a clean component checkout;
|
||||
* only ``modules/**/*.mq.md`` is published. Other files under ``modules/``
|
||||
(for example ``modules/README.md``) stay repository documentation and are
|
||||
not packed. Symlinks, submodules and non-regular entries are refused;
|
||||
* published paths must be NFC, case-insensitively unique and free of
|
||||
``tests/``, ``.git`` or traversal segments;
|
||||
* a version bump is explicit: with ``--baseline-manifest`` content digest
|
||||
changes are refused unless ``version`` also changes.
|
||||
|
||||
Usage:
|
||||
|
||||
python3 scripts/build-stdlib.py --out build/stdlib
|
||||
python3 scripts/build-stdlib.py --out build/stdlib --worktree
|
||||
python3 scripts/build-stdlib.py --out build/stdlib \
|
||||
--baseline-manifest previous/stdlib.json
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import tomllib
|
||||
import unicodedata
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DEFAULT_CONFIG = Path("scripts") / "stdlib-bundle.json"
|
||||
MANIFEST = "stdlib.json"
|
||||
MODULES = "modules"
|
||||
PUBLISHED_SUFFIX = ".mq.md"
|
||||
|
||||
|
||||
class BundleError(Exception):
|
||||
"""An input cannot become the official Bundle."""
|
||||
|
||||
|
||||
def _git(repo: Path, *args: str) -> bytes:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(repo), *args], capture_output=True
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise BundleError(
|
||||
f"git failed in {repo}: {' '.join(args)}: "
|
||||
f"{result.stderr.decode(errors='replace').strip()}"
|
||||
)
|
||||
return result.stdout
|
||||
|
||||
|
||||
def _nfc(value: str) -> str:
|
||||
return unicodedata.normalize("NFC", value)
|
||||
|
||||
|
||||
def load_json(path: Path) -> dict:
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error:
|
||||
raise BundleError(f"cannot read {path}: {error}") from error
|
||||
if not isinstance(data, dict):
|
||||
raise BundleError(f"{path} must contain a JSON object")
|
||||
return data
|
||||
|
||||
|
||||
def read_blob(repo: Path, revision: str, path: str) -> bytes | None:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(repo), "show", f"{revision}:{path}"],
|
||||
capture_output=True,
|
||||
)
|
||||
return result.stdout if result.returncode == 0 else None
|
||||
|
||||
|
||||
def read_catalog(root: Path, revision: str | None) -> list[dict]:
|
||||
if revision is None:
|
||||
raw = (root / "components.toml").read_bytes()
|
||||
else:
|
||||
raw = read_blob(root, revision, "components.toml")
|
||||
if raw is None:
|
||||
raise BundleError(f"root commit {revision} has no components.toml")
|
||||
try:
|
||||
catalog = tomllib.loads(raw.decode("utf-8"))
|
||||
except (UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
|
||||
raise BundleError(f"invalid components.toml: {error}") from error
|
||||
components = catalog.get("component")
|
||||
if not isinstance(components, list):
|
||||
raise BundleError("components.toml has no [[component]] entries")
|
||||
return components
|
||||
|
||||
|
||||
def read_config(root: Path, revision: str | None, path: Path) -> dict:
|
||||
if not path.is_absolute():
|
||||
path = root / path
|
||||
if revision is not None:
|
||||
relative = path.resolve().relative_to(root.resolve()).as_posix()
|
||||
raw = read_blob(root, revision, relative)
|
||||
if raw is None:
|
||||
raise BundleError(f"root commit {revision} has no {relative}")
|
||||
try:
|
||||
config = json.loads(raw.decode("utf-8"))
|
||||
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
||||
raise BundleError(f"invalid Bundle config {relative}: {error}") from error
|
||||
else:
|
||||
config = load_json(path)
|
||||
for field in ("name", "version"):
|
||||
value = config.get(field)
|
||||
if not isinstance(value, str) or not value:
|
||||
raise BundleError(f"Bundle config has no non-empty `{field}`")
|
||||
aliases = config.get("public_aliases", [])
|
||||
if not isinstance(aliases, list):
|
||||
raise BundleError("Bundle config `public_aliases` must be a list")
|
||||
return config
|
||||
|
||||
|
||||
def pinned_gitlink(root: Path, revision: str, path: str) -> str:
|
||||
result = _git(root, "ls-tree", revision, "--", path).decode().strip()
|
||||
if not result:
|
||||
raise BundleError(
|
||||
f"root commit {revision} has no gitlink at {path}; only published "
|
||||
"components may join the Bundle"
|
||||
)
|
||||
fields = result.split()
|
||||
if len(fields) != 4:
|
||||
raise BundleError(f"invalid gitlink record for {path}")
|
||||
mode, kind, sha, _ = fields
|
||||
if mode != "160000" or kind != "commit":
|
||||
raise BundleError(f"{path} is not a gitlink in root commit {revision}")
|
||||
return sha
|
||||
|
||||
|
||||
def worktree_sha(component_dir: Path) -> str:
|
||||
if not (component_dir / ".git").exists():
|
||||
raise BundleError(f"missing component checkout: {component_dir}")
|
||||
status = _git(component_dir, "status", "--porcelain").decode().strip()
|
||||
if status:
|
||||
raise BundleError(f"dirty component checkout: {component_dir}")
|
||||
return _git(component_dir, "rev-parse", "HEAD").decode().strip()
|
||||
|
||||
|
||||
def validate_published_path(relative: str, component_id: str) -> None:
|
||||
if not relative or relative.startswith("/"):
|
||||
raise BundleError(f"{component_id}: invalid published path {relative!r}")
|
||||
parts = relative.split("/")
|
||||
if any(part in ("", ".", "..") for part in parts):
|
||||
raise BundleError(f"{component_id}: unsafe published path {relative!r}")
|
||||
if any(part.startswith(".") for part in parts):
|
||||
raise BundleError(f"{component_id}: hidden path segment in {relative!r}")
|
||||
if "tests" in parts:
|
||||
raise BundleError(f"{component_id}: tests must not enter the Bundle: {relative!r}")
|
||||
if not relative.endswith(PUBLISHED_SUFFIX):
|
||||
raise BundleError(
|
||||
f"{component_id}: only {PUBLISHED_SUFFIX} files are published, got {relative!r}"
|
||||
)
|
||||
if _nfc(relative) != relative:
|
||||
raise BundleError(
|
||||
f"{component_id}: published path is not NFC normalised: {relative!r}"
|
||||
)
|
||||
|
||||
|
||||
def component_modules(component_dir: Path, revision: str, component_id: str) -> list[tuple[str, str]]:
|
||||
output = _git(
|
||||
component_dir, "ls-tree", "-r", "-z", revision, "--", MODULES
|
||||
)
|
||||
records = [record for record in output.split(b"\0") if record]
|
||||
published: list[tuple[str, str]] = []
|
||||
for record in records:
|
||||
header, _, raw_path = record.partition(b"\t")
|
||||
fields = header.decode().split()
|
||||
if len(fields) != 3:
|
||||
raise BundleError(f"{component_id}: invalid tree record {record!r}")
|
||||
mode, kind, sha = fields
|
||||
path = raw_path.decode()
|
||||
if kind != "blob" or mode not in ("100644", "100755"):
|
||||
raise BundleError(
|
||||
f"{component_id}: only regular modules files are publishable, "
|
||||
f"found {mode} {kind} at {path}"
|
||||
)
|
||||
relative = path[len(MODULES) + 1 :]
|
||||
if not relative.endswith(PUBLISHED_SUFFIX):
|
||||
continue
|
||||
validate_published_path(relative, component_id)
|
||||
published.append((relative, sha))
|
||||
if not published:
|
||||
raise BundleError(
|
||||
f"{component_id}: active component publishes no {PUBLISHED_SUFFIX} modules"
|
||||
)
|
||||
return published
|
||||
|
||||
|
||||
def collect(root: Path, components: list[dict], *, root_commit: str | None) -> tuple[dict[str, bytes], list[dict]]:
|
||||
active = [
|
||||
component
|
||||
for component in components
|
||||
if component.get("kind") == "stdlib" and component.get("state") == "active"
|
||||
]
|
||||
if not active:
|
||||
raise BundleError("no active stdlib component; nothing to publish")
|
||||
for component in active:
|
||||
if component.get("release") != "base":
|
||||
raise BundleError(
|
||||
f'{component["id"]}: active stdlib component must have release = "base"'
|
||||
)
|
||||
files: dict[str, bytes] = {}
|
||||
identities: list[dict] = []
|
||||
owners: dict[str, str] = {}
|
||||
folded: dict[str, str] = {}
|
||||
for component in active:
|
||||
component_id = component["id"]
|
||||
path = component["path"]
|
||||
component_dir = (root / path).resolve()
|
||||
revision = (
|
||||
pinned_gitlink(root, root_commit, path)
|
||||
if root_commit is not None
|
||||
else worktree_sha(component_dir)
|
||||
)
|
||||
modules = component_modules(component_dir, revision, component_id)
|
||||
for relative, sha in modules:
|
||||
key = _nfc(relative).casefold()
|
||||
if relative in owners:
|
||||
raise BundleError(
|
||||
f"duplicate published path {relative!r}: "
|
||||
f"{owners[relative]} and {component_id}"
|
||||
)
|
||||
if key in folded:
|
||||
raise BundleError(
|
||||
f"case/NFC collision on {relative!r}: "
|
||||
f"{folded[key]} and {component_id}"
|
||||
)
|
||||
owners[relative] = component_id
|
||||
folded[key] = component_id
|
||||
files[relative] = _git(component_dir, "cat-file", "blob", sha)
|
||||
identities.append(
|
||||
{"id": component_id, "path": path, "revision": revision, "files": len(modules)}
|
||||
)
|
||||
return files, identities
|
||||
|
||||
|
||||
def tree_digest(files: dict[str, bytes]) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for relative in sorted(files):
|
||||
digest.update(relative.encode())
|
||||
digest.update(b"\0")
|
||||
digest.update(files[relative])
|
||||
digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def aliases_digest(aliases: list[dict]) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for alias in sorted(
|
||||
aliases, key=lambda item: (item["target_module"], item["target_function"])
|
||||
):
|
||||
digest.update(alias["target_module"].encode())
|
||||
digest.update(b"\0")
|
||||
digest.update(alias["target_function"].encode())
|
||||
digest.update(b"\0")
|
||||
for name in sorted(alias["public_names"]):
|
||||
digest.update(name.encode())
|
||||
digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def validate_aliases(aliases: list[dict], files: dict[str, bytes]) -> None:
|
||||
seen: set[str] = set()
|
||||
for alias in aliases:
|
||||
if not isinstance(alias, dict):
|
||||
raise BundleError("public alias entry must be an object")
|
||||
module = alias.get("target_module")
|
||||
function = alias.get("target_function")
|
||||
names = alias.get("public_names")
|
||||
if module not in files:
|
||||
raise BundleError(f"public alias targets missing module: {module!r}")
|
||||
if not isinstance(function, str) or not function:
|
||||
raise BundleError(f"public alias for {module} has no target_function")
|
||||
if not isinstance(names, list) or not names or not all(
|
||||
isinstance(name, str) and name for name in names
|
||||
):
|
||||
raise BundleError(f"public alias for {module}.{function} has invalid names")
|
||||
for name in names:
|
||||
if name in seen:
|
||||
raise BundleError(f"public alias name declared twice: {name!r}")
|
||||
seen.add(name)
|
||||
if alias.get("expected_signature") != "params(值)":
|
||||
raise BundleError(
|
||||
f"public alias {module}.{function} must keep expected_signature params(值)"
|
||||
)
|
||||
if alias.get("effects") != ["host"]:
|
||||
raise BundleError(
|
||||
f"public alias {module}.{function} must keep effects [host]"
|
||||
)
|
||||
|
||||
|
||||
def build_manifest(config: dict, files: dict[str, bytes]) -> dict:
|
||||
aliases = config.get("public_aliases", [])
|
||||
validate_aliases(aliases, files)
|
||||
return {
|
||||
"name": config["name"],
|
||||
"version": config["version"],
|
||||
"digest": tree_digest(files),
|
||||
"public_aliases": aliases,
|
||||
"aliases_digest": aliases_digest(aliases),
|
||||
}
|
||||
|
||||
|
||||
def check_baseline(manifest: dict, baseline_path: Path) -> None:
|
||||
baseline = load_json(baseline_path)
|
||||
if baseline.get("version") == manifest["version"] and baseline.get(
|
||||
"digest"
|
||||
) != manifest["digest"]:
|
||||
raise BundleError(
|
||||
f"Bundle content changed but version is still {manifest['version']}; "
|
||||
"bump the version explicitly"
|
||||
)
|
||||
|
||||
|
||||
def write_bundle(out: Path, manifest: dict, files: dict[str, bytes], force: bool) -> None:
|
||||
if out.exists():
|
||||
if not force:
|
||||
raise BundleError(f"output directory already exists: {out}")
|
||||
shutil.rmtree(out)
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
staging = Path(tempfile.mkdtemp(prefix=".stdlib-build-", dir=str(out.parent)))
|
||||
try:
|
||||
for relative, data in files.items():
|
||||
target = staging / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
(staging / MANIFEST).write_text(
|
||||
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
os.replace(staging, out)
|
||||
except BaseException:
|
||||
shutil.rmtree(staging, ignore_errors=True)
|
||||
raise
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--out", required=True, help="Bundle output directory")
|
||||
parser.add_argument("--root-commit", default=None)
|
||||
parser.add_argument("--worktree", action="store_true")
|
||||
parser.add_argument("--config", default=None)
|
||||
parser.add_argument("--baseline-manifest", default=None)
|
||||
parser.add_argument("--force", action="store_true")
|
||||
parser.add_argument("--root", default=str(ROOT), help=argparse.SUPPRESS)
|
||||
args = parser.parse_args(argv)
|
||||
if args.worktree and args.root_commit:
|
||||
parser.error("--worktree and --root-commit are mutually exclusive")
|
||||
root = Path(args.root).resolve()
|
||||
revision = None
|
||||
if not args.worktree:
|
||||
revision = args.root_commit or _git(root, "rev-parse", "HEAD").decode().strip()
|
||||
try:
|
||||
components = read_catalog(root, revision)
|
||||
config = read_config(root, revision, Path(args.config) if args.config else DEFAULT_CONFIG)
|
||||
files, identities = collect(root, components, root_commit=revision)
|
||||
manifest = build_manifest(config, files)
|
||||
if args.baseline_manifest:
|
||||
check_baseline(manifest, Path(args.baseline_manifest))
|
||||
except BundleError as error:
|
||||
raise SystemExit(f"build-stdlib: error: {error}") from error
|
||||
write_bundle(Path(args.out), manifest, files, args.force)
|
||||
summary = {
|
||||
"name": manifest["name"],
|
||||
"version": manifest["version"],
|
||||
"tree_digest": manifest["digest"],
|
||||
"aliases_digest": manifest["aliases_digest"],
|
||||
"root_commit": revision,
|
||||
"components": identities,
|
||||
"files": sorted(files),
|
||||
}
|
||||
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
@@ -1,317 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify one candidate notification before any automation acts on it.
|
||||
|
||||
The ecosystem uses manual PR gates; this verifier is the authorization step for
|
||||
a (future) bot that may only create candidate branches/PRs. It accepts a
|
||||
normalized notification (from a reviewed webhook adapter), never a raw remote
|
||||
payload, and returns a machine plan. It refuses forged, replayed, stale,
|
||||
unknown or failed candidates instead of trusting the sender.
|
||||
|
||||
Checks, in order:
|
||||
|
||||
1. notification schema and 40-hex commits;
|
||||
2. the repository is an allowlisted component remote (or the root repository);
|
||||
3. the CI result is `success` on an allowlisted CI host with an https URL;
|
||||
4. the commit is reachable in the owning local repository;
|
||||
5. a component candidate starts from the exact SHA currently pinned by the
|
||||
accepted root graph (a stale/retargeted base is rejected);
|
||||
6. the (repository, head SHA) pair is not a replay; a new accepted baseline
|
||||
allows a re-validation and marks the result `revalidate`;
|
||||
7. impact is computed with the shared union-graph analyzer; undetermined scope
|
||||
widens to full re-validation instead of skipping.
|
||||
|
||||
The verifier never merges, pushes, grants permissions or fetches floating
|
||||
branches. Its only proposed action is recording the candidate / creating a
|
||||
candidate branch that a human still reviews.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import datetime as dt
|
||||
import importlib.util
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
import urllib.parse
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
ROOT = PROJECT_ROOT
|
||||
SCHEMA = "marqdo.candidate-notification"
|
||||
PLAN_SCHEMA = "marqdo.candidate-plan"
|
||||
SCHEMA_VERSION = 1
|
||||
DEFAULT_CI_HOST = "ci.cflmy.cn"
|
||||
|
||||
|
||||
def load_impact():
|
||||
"""Load the shared analyzer and point it at the verifier's root checkout."""
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"marqdo_impact", PROJECT_ROOT / "scripts" / "impact.py"
|
||||
)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
module.ROOT = ROOT
|
||||
return module
|
||||
|
||||
|
||||
def git(repo: Path, *args: str) -> str:
|
||||
result = subprocess.run(["git", "-C", str(repo), *args], capture_output=True)
|
||||
if result.returncode != 0:
|
||||
raise NotificationError(
|
||||
f"git {' '.join(args)} failed in {repo}: "
|
||||
f"{result.stderr.decode(errors='replace').strip()}"
|
||||
)
|
||||
return result.stdout.decode(errors="replace")
|
||||
|
||||
|
||||
class NotificationError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def is_sha(value) -> bool:
|
||||
return isinstance(value, str) and len(value) == 40 and all(
|
||||
ch in "0123456789abcdef" for ch in value
|
||||
)
|
||||
|
||||
|
||||
def repository_allowlist(accepted_revision: str) -> dict[str, dict]:
|
||||
"""Map `owner/name` -> component identity from the accepted root graph."""
|
||||
impact = load_impact()
|
||||
graph, unverified = impact.load_graph(ROOT, accepted_revision, "root")
|
||||
if unverified:
|
||||
raise NotificationError(
|
||||
"accepted graph cannot be expanded: " + "; ".join(unverified)
|
||||
)
|
||||
allowlist: dict[str, dict] = {}
|
||||
for component in graph.values():
|
||||
remote = component.get("remote")
|
||||
if not remote:
|
||||
continue
|
||||
parsed = urllib.parse.urlparse(remote)
|
||||
name = parsed.path.strip("/")
|
||||
if name.endswith(".git"):
|
||||
name = name[:-4]
|
||||
if name:
|
||||
allowlist[name] = component
|
||||
return allowlist
|
||||
|
||||
|
||||
def check_schema(notification: dict) -> None:
|
||||
if notification.get("schema") != SCHEMA:
|
||||
raise NotificationError(f"unsupported notification schema: {notification.get('schema')!r}")
|
||||
if notification.get("schema_version") != SCHEMA_VERSION:
|
||||
raise NotificationError("unsupported notification schema_version")
|
||||
if notification.get("kind") not in ("component", "root"):
|
||||
raise NotificationError("kind must be 'component' or 'root'")
|
||||
for field in ("repository", "head_sha", "base_sha"):
|
||||
if not isinstance(notification.get(field), str) or not notification[field]:
|
||||
raise NotificationError(f"notification has no {field}")
|
||||
if not is_sha(notification["head_sha"]) or not is_sha(notification["base_sha"]):
|
||||
raise NotificationError("head_sha/base_sha must be full lowercase commit SHAs")
|
||||
if notification["head_sha"] == notification["base_sha"]:
|
||||
raise NotificationError("head_sha equals base_sha; nothing to verify")
|
||||
|
||||
|
||||
def check_ci(notification: dict, ci_hosts: list[str]) -> dict:
|
||||
ci = notification.get("ci")
|
||||
if not isinstance(ci, dict):
|
||||
raise NotificationError("notification has no ci object")
|
||||
if ci.get("status") != "success":
|
||||
raise NotificationError(f"CI status is not success: {ci.get('status')!r}")
|
||||
url = ci.get("url")
|
||||
if not isinstance(url, str):
|
||||
raise NotificationError("notification ci.url must be a string")
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
if parsed.scheme != "https" or parsed.hostname not in ci_hosts:
|
||||
raise NotificationError(
|
||||
f"CI URL must be https on one of {ci_hosts}: {url!r}"
|
||||
)
|
||||
return ci
|
||||
|
||||
|
||||
def load_state(path: Path) -> dict:
|
||||
if not path.is_file():
|
||||
return {"schema": "marqdo.candidate-state", "schema_version": 1, "seen": {}}
|
||||
state = json.loads(path.read_text())
|
||||
if not isinstance(state.get("seen"), dict):
|
||||
raise NotificationError(f"invalid candidate state file: {path}")
|
||||
return state
|
||||
|
||||
|
||||
def verify(
|
||||
notification: dict,
|
||||
accepted_ref: str,
|
||||
state_path: Path,
|
||||
ci_hosts: list[str],
|
||||
root_repository: str,
|
||||
write_state: bool,
|
||||
) -> dict:
|
||||
check_schema(notification)
|
||||
ci = check_ci(notification, ci_hosts)
|
||||
impact = load_impact()
|
||||
impact.ROOT = ROOT
|
||||
accepted_revision = impact.resolve(ROOT, accepted_ref)
|
||||
reasons: list[str] = []
|
||||
revalidate = False
|
||||
kind = notification["kind"]
|
||||
repository = notification["repository"]
|
||||
allowlist = repository_allowlist(accepted_revision)
|
||||
if kind == "root":
|
||||
if repository != root_repository:
|
||||
raise NotificationError(
|
||||
f"unknown root repository {repository!r}; allowlist is {root_repository!r}"
|
||||
)
|
||||
if not subprocess.run(
|
||||
["git", "-C", str(ROOT), "cat-file", "-e", notification["head_sha"] + "^{commit}"],
|
||||
capture_output=True,
|
||||
).returncode == 0:
|
||||
raise NotificationError("candidate commit is not reachable in the root repository")
|
||||
report = impact.analyze(accepted_revision, notification["head_sha"])
|
||||
base_sha = accepted_revision
|
||||
key = f"root@{notification['head_sha']}"
|
||||
else:
|
||||
component = allowlist.get(repository)
|
||||
if component is None:
|
||||
raise NotificationError(
|
||||
f"unknown repository {repository!r}; allowlist: {sorted(allowlist)}"
|
||||
)
|
||||
component_id = notification.get("component") or component["id"]
|
||||
if component_id != component["id"]:
|
||||
raise NotificationError(
|
||||
f"notification component {component_id!r} does not own repository {repository!r}"
|
||||
)
|
||||
checkout = ROOT / component["path"]
|
||||
if not (checkout / ".git").exists():
|
||||
raise NotificationError(f"missing component checkout: {checkout}")
|
||||
if not subprocess.run(
|
||||
["git", "-C", str(checkout), "cat-file", "-e", notification["head_sha"] + "^{commit}"],
|
||||
capture_output=True,
|
||||
).returncode == 0:
|
||||
raise NotificationError("candidate commit is not reachable in the component repository")
|
||||
if component.get("sha") != notification["base_sha"]:
|
||||
raise NotificationError(
|
||||
"base_sha is stale: the accepted root graph pins "
|
||||
f"{component.get('sha')} for {component_id}"
|
||||
)
|
||||
report = impact.consumers_of(component_id, accepted_revision)
|
||||
base_sha = component["sha"]
|
||||
key = f"{repository}@{notification['head_sha']}"
|
||||
state = load_state(state_path)
|
||||
previous = state["seen"].get(key)
|
||||
if previous is not None:
|
||||
if previous.get("accepted") == accepted_revision:
|
||||
raise NotificationError(
|
||||
"duplicate/replay: this candidate was already verified against the same accepted baseline"
|
||||
)
|
||||
revalidate = True
|
||||
reasons.append(
|
||||
"new accepted baseline since first notification; re-run the full candidate gates"
|
||||
)
|
||||
if report.get("unverified"):
|
||||
reasons.append("impact scope undetermined; full re-validation required")
|
||||
state["seen"][key] = {
|
||||
"accepted": accepted_revision,
|
||||
"base_sha": base_sha,
|
||||
"kind": kind,
|
||||
"repository": repository,
|
||||
"first_verified": previous.get("first_verified")
|
||||
if previous
|
||||
else dt.datetime.now(dt.timezone.utc).isoformat(),
|
||||
"last_verified": dt.datetime.now(dt.timezone.utc).isoformat(),
|
||||
}
|
||||
if write_state:
|
||||
state_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
state_path.write_text(json.dumps(state, indent=2) + "\n")
|
||||
return {
|
||||
"schema": PLAN_SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"verified": True,
|
||||
"revalidate": revalidate,
|
||||
"reasons": reasons,
|
||||
"kind": kind,
|
||||
"repository": repository,
|
||||
"head_sha": notification["head_sha"],
|
||||
"base_sha": notification["base_sha"],
|
||||
"accepted": {"ref": accepted_ref, "revision": accepted_revision},
|
||||
"ci": ci,
|
||||
"impact": {
|
||||
"affected": report.get("affected", []),
|
||||
"changed": report.get("changed", []),
|
||||
"checks_with": report.get("checks_with", []),
|
||||
"fallback": report.get("fallback"),
|
||||
"unverified": report.get("unverified", []),
|
||||
},
|
||||
"actions": {
|
||||
"auto_promote": False,
|
||||
"auto_merge": False,
|
||||
"create_candidate_branch": True,
|
||||
"requires_human_review": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--notification", required=True, help="normalized notification JSON")
|
||||
parser.add_argument("--accepted", required=True, help="accepted root revision")
|
||||
parser.add_argument("--state", required=True, help="candidate dedupe state file")
|
||||
parser.add_argument(
|
||||
"--ci-host", action="append", default=None, help="allowlisted CI host (repeatable)"
|
||||
)
|
||||
parser.add_argument("--root-repository", default="cflmy/marqdo")
|
||||
parser.add_argument("--out", default=None)
|
||||
parser.add_argument("--json", action="store_true")
|
||||
parser.add_argument("--dry-run", action="store_true", help="do not write the dedupe state")
|
||||
args = parser.parse_args(argv)
|
||||
ci_hosts = args.ci_host or [DEFAULT_CI_HOST]
|
||||
try:
|
||||
notification = json.loads(Path(args.notification).read_text())
|
||||
if not isinstance(notification, dict):
|
||||
raise NotificationError("notification must be a JSON object")
|
||||
plan = verify(
|
||||
notification,
|
||||
args.accepted,
|
||||
Path(args.state),
|
||||
ci_hosts,
|
||||
args.root_repository,
|
||||
write_state=not args.dry_run,
|
||||
)
|
||||
except (NotificationError, json.JSONDecodeError, OSError) as error:
|
||||
rejected = {
|
||||
"schema": PLAN_SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"verified": False,
|
||||
"reasons": [str(error)],
|
||||
"actions": {
|
||||
"auto_promote": False,
|
||||
"auto_merge": False,
|
||||
"create_candidate_branch": False,
|
||||
"requires_human_review": True,
|
||||
},
|
||||
}
|
||||
text = json.dumps(rejected, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.out:
|
||||
Path(args.out).write_text(text)
|
||||
if args.json:
|
||||
print(text, end="")
|
||||
print(f"candidate-notify: rejected: {error}", file=sys.stderr)
|
||||
return 1
|
||||
text = json.dumps(plan, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.out:
|
||||
Path(args.out).write_text(text)
|
||||
if args.json:
|
||||
print(text, end="")
|
||||
else:
|
||||
print(
|
||||
f"verified {plan['kind']} candidate {plan['repository']}@{plan['head_sha'][:12]} "
|
||||
f"affected={len(plan['impact']['affected'])} revalidate={plan['revalidate']}"
|
||||
)
|
||||
for reason in plan["reasons"]:
|
||||
print(f" note: {reason}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
@@ -1,455 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Validate a Marqdo ecosystem Git tree.
|
||||
|
||||
The checker follows the hierarchical governance rules of the Marqdo ecosystem
|
||||
specification (sections 2-4, 13):
|
||||
|
||||
* the root catalog describes direct components and domain aggregates;
|
||||
* a registered ``kind = "domain"`` gitlink is expanded at its exact pinned
|
||||
commit for ``--checkouts`` or to validate URLs before updating its children;
|
||||
* each aggregate layer has its own ``components.toml`` / ``.gitmodules`` and
|
||||
registers only its direct children;
|
||||
* governance depth is limited to two gitlink levels (root -> domain -> leaf);
|
||||
* global ids and remotes are unique, dependency edges resolve globally and
|
||||
``requires`` stays acyclic while ``checks_with`` may contain cycles.
|
||||
|
||||
Commit identity comes from the Git tree (gitlinks), the authority for remotes
|
||||
is ``.gitmodules`` and the catalog never repeats SHAs. The checker never
|
||||
fetches from a network remote, never runs ``git submodule update`` and only
|
||||
reads objects already present in the local repositories.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import graphlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
import unicodedata
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
NAME = r"[a-z][a-z0-9]*(?:-[a-z0-9]+)*"
|
||||
FIELDS = {"id", "path", "kind", "state", "owner", "scope", "requires", "checks_with", "release"}
|
||||
ROOT_FILES = {".gitattributes", ".gitignore", ".gitmodules", "AGENTS.md", "LICENSE", "README.md", "components.toml"}
|
||||
ROOT_DIRS = {".gitea", ".woodpecker", "docs", "examples", "scripts"}
|
||||
CATEGORY_READMES = {"stdlib/README.md", "extensions/README.md"}
|
||||
RELEASE_ROLES = {"core": "base", "stdlib": "base", "extension": "optional", "tool": "optional", "test": "none"}
|
||||
DOMAIN_RELEASE = {"none", "base"}
|
||||
DOMAIN_FILES = {".gitattributes", ".gitignore", ".gitmodules", "AGENTS.md", "LICENSE", "README.md", "components.toml"}
|
||||
DOMAIN_DIRS = {".gitea", ".woodpecker", "docs", "examples", "scripts", "tests"}
|
||||
DOMAIN_CHILD_KINDS = {"stdlib", "extension", "tool"}
|
||||
AUTHORITY = "https://git.cflmy.cn/cflmy"
|
||||
ENTRY = r"(?:[a-zA-Z0-9_-]+/)*[a-zA-Z0-9_-][a-zA-Z0-9_.-]*"
|
||||
|
||||
|
||||
def git(*args, cwd=ROOT):
|
||||
return subprocess.check_output(["git", "-C", str(cwd), *args]).decode()
|
||||
|
||||
|
||||
def require(condition, message):
|
||||
if not condition:
|
||||
raise ValueError(message)
|
||||
|
||||
|
||||
def nfc(value):
|
||||
return unicodedata.normalize("NFC", value)
|
||||
|
||||
|
||||
class Layer:
|
||||
"""One governance level: the root tree or one expanded domain aggregate."""
|
||||
|
||||
def __init__(self, repo, revision, label, depth, order, components, gitlinks, linked, urls):
|
||||
self.repo = Path(repo)
|
||||
self.revision = revision
|
||||
self.label = label
|
||||
self.depth = depth
|
||||
self.order = order
|
||||
self.components = components
|
||||
self.gitlinks = gitlinks
|
||||
self.linked = linked
|
||||
self.urls = urls
|
||||
|
||||
|
||||
def read_blob(repo, revision, path, label):
|
||||
try:
|
||||
return git("show", f"{revision}:{path}", cwd=repo)
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
|
||||
def check_relative_path(path, id, label):
|
||||
require(isinstance(path, str) and path, f"{label}: invalid path for {id}: {path!r}")
|
||||
require("\\" not in path and not path.startswith("/") and not path.endswith("/"),
|
||||
f"{label}: invalid path for {id}: {path!r}")
|
||||
segments = path.split("/")
|
||||
require(all(segment and segment not in {".", ".."} for segment in segments),
|
||||
f"{label}: invalid path for {id}: {path!r}")
|
||||
require(all(re.fullmatch(NAME, segment) for segment in segments),
|
||||
f"{label}: invalid path for {id}: {path!r}")
|
||||
require(nfc(path) == path, f"{label}: non-NFC path for {id}: {path!r}")
|
||||
return path
|
||||
|
||||
|
||||
def expected_root_path(component):
|
||||
kind = component["kind"]
|
||||
id = component["id"]
|
||||
if kind == "core":
|
||||
return "cli" if id == "cli" else None
|
||||
if kind == "test":
|
||||
return "tests/conformance" if id == "conformance" else None
|
||||
if kind == "stdlib":
|
||||
return f"stdlib/{id.removeprefix('std-')}" if id.startswith("std-") else None
|
||||
if kind == "extension":
|
||||
return f"extensions/{id}"
|
||||
if kind == "tool":
|
||||
return f"tools/{id}"
|
||||
if kind == "domain":
|
||||
return "stdlib" if id == "stdlib" else f"extensions/{id}"
|
||||
return None
|
||||
|
||||
|
||||
def expected_remote(component, depth):
|
||||
"""Derive the single approved self-hosted HTTPS remote for a component.
|
||||
|
||||
Root direct components keep their historical ``marqdo-<id>`` /
|
||||
``marqdo-ext-<id>`` / ``marqdo-extension-conformance`` repository names.
|
||||
Components registered by a domain aggregate are independently named
|
||||
``marqdo-<id>`` (for example ``marqdo-web-design``).
|
||||
"""
|
||||
id = component["id"]
|
||||
kind = component["kind"]
|
||||
if depth == 0:
|
||||
if kind == "test":
|
||||
name = "extension-conformance"
|
||||
elif kind == "extension":
|
||||
name = f"ext-{id}"
|
||||
elif kind == "domain":
|
||||
name = "stdlib" if id == "stdlib" else f"ext-{id}"
|
||||
else:
|
||||
name = id
|
||||
else:
|
||||
name = id
|
||||
return f"{AUTHORITY}/marqdo-{name}.git"
|
||||
|
||||
|
||||
def check_component(raw, depth, label, by_id, paths, path_keys):
|
||||
require(isinstance(raw, dict), f"{label}: invalid component entry: {raw!r}")
|
||||
id = raw.get("id")
|
||||
state = raw.get("state")
|
||||
require(state in {"active", "planned"}, f"{label}: invalid state: {id!r}")
|
||||
fields = FIELDS | ({"entry"} if state == "active" else set())
|
||||
require(set(raw) == fields, f"{label}: invalid fields for {id!r}: {sorted(set(raw) ^ fields)}")
|
||||
require(isinstance(id, str) and re.fullmatch(NAME, id), f"{label}: invalid id: {id!r}")
|
||||
|
||||
for key in ("requires", "checks_with"):
|
||||
items = raw[key]
|
||||
require(isinstance(items, list) and all(isinstance(item, str) for item in items),
|
||||
f"{label}: invalid {key}: {id}")
|
||||
require(id not in items and len(set(items)) == len(items), f"{label}: invalid {key}: {id}")
|
||||
|
||||
kind = raw["kind"]
|
||||
require(kind in RELEASE_ROLES or kind == "domain", f"{label}: unknown kind: {id}: {kind!r}")
|
||||
if kind == "domain":
|
||||
require(depth == 0, f"{label}: domain kind is only allowed at the root layer: {id}")
|
||||
require(raw["release"] in DOMAIN_RELEASE, f"{label}: invalid release role: {id}")
|
||||
require(raw["requires"] == [], f"{label}: domain requires must be empty: {id}")
|
||||
else:
|
||||
require(depth == 0 or kind in DOMAIN_CHILD_KINDS,
|
||||
f"{label}: component kind is not allowed inside a domain: {id} ({kind})")
|
||||
require(raw["release"] == RELEASE_ROLES[kind], f"{label}: invalid release role: {id}")
|
||||
|
||||
path = check_relative_path(raw["path"], id, label)
|
||||
if depth == 0:
|
||||
expected = expected_root_path(raw)
|
||||
require(expected is not None and path == expected,
|
||||
f"{label}: invalid path: {id}: {path} (expected {expected})")
|
||||
require(path not in paths, f"{label}: invalid or duplicate path: {path}")
|
||||
key = nfc(path).casefold()
|
||||
require(key not in path_keys, f"{label}: path case/NFC conflict: {id}: {path}")
|
||||
for other in paths:
|
||||
require(not path.startswith(other + "/") and not other.startswith(path + "/"),
|
||||
f"{label}: overlapping component path: {path} / {other}")
|
||||
|
||||
for key in ("owner", "scope"):
|
||||
require(isinstance(raw[key], str) and raw[key].strip(), f"{label}: missing {key}: {id}")
|
||||
if state == "active":
|
||||
require(isinstance(raw["entry"], str) and re.fullmatch(ENTRY, raw["entry"]),
|
||||
f"{label}: unsafe entry: {id}")
|
||||
|
||||
paths.add(path)
|
||||
path_keys.add(key)
|
||||
by_id[id] = raw
|
||||
return raw
|
||||
|
||||
|
||||
def parse_catalog(repo, revision, label):
|
||||
text = read_blob(repo, revision, "components.toml", label)
|
||||
require(text is not None, f"{label}: missing components.toml at {revision}")
|
||||
try:
|
||||
data = tomllib.loads(text)
|
||||
except tomllib.TOMLDecodeError as error:
|
||||
raise ValueError(f"{label}: invalid components.toml: {error}") from None
|
||||
require(set(data) == {"component"} and isinstance(data["component"], list), f"{label}: invalid catalog")
|
||||
return data["component"]
|
||||
|
||||
|
||||
def tree_entries(repo, revision, label):
|
||||
try:
|
||||
output = git("ls-tree", "-rz", "--full-tree", revision, cwd=repo)
|
||||
except subprocess.CalledProcessError:
|
||||
raise ValueError(f"{label}: missing Git tree at {revision}") from None
|
||||
entries = {}
|
||||
for record in output.split("\0"):
|
||||
if record:
|
||||
metadata, path = record.split("\t", 1)
|
||||
mode, _, sha = metadata.split()
|
||||
entries[path] = (mode, sha)
|
||||
return entries
|
||||
|
||||
|
||||
def check_root_tree(entries, linked, unlinked, label):
|
||||
allowed_readmes = CATEGORY_READMES | {
|
||||
f'{item["path"]}/README.md'
|
||||
for item in unlinked
|
||||
if item["kind"] in {"stdlib", "extension", "domain"}
|
||||
}
|
||||
for path, (mode, _) in entries.items():
|
||||
root = path.split("/", 1)[0]
|
||||
require(
|
||||
path in linked or (mode == "100644" and path in allowed_readmes)
|
||||
or (mode in {"100644", "100755"} and (
|
||||
path in ROOT_FILES or root in ROOT_DIRS and "/" in path or path.startswith("tests/integration/")
|
||||
)),
|
||||
f"{label}: unexpected tracked path or mode: {path} ({mode})",
|
||||
)
|
||||
|
||||
|
||||
def check_domain_tree(entries, linked, unlinked, label):
|
||||
"""Aggregate layers only carry governance, docs, examples and tests.
|
||||
|
||||
Production implementations stay in the child repositories: an aggregate
|
||||
may not add a renderer, parser or driver under its own tree.
|
||||
"""
|
||||
allowed_readmes = {f'{item["path"]}/README.md' for item in unlinked}
|
||||
for path, (mode, _) in entries.items():
|
||||
if path in linked:
|
||||
continue
|
||||
if mode == "100644" and path in allowed_readmes:
|
||||
continue
|
||||
top = path.split("/", 1)[0]
|
||||
top_level_doc = mode == "100644" and "/" not in path and path.endswith(".md")
|
||||
require(
|
||||
mode in {"100644", "100755"} and (
|
||||
path in DOMAIN_FILES or top_level_doc or (top in DOMAIN_DIRS and "/" in path)
|
||||
),
|
||||
f"{label}: unexpected aggregate tracked path or mode: {path} ({mode})",
|
||||
)
|
||||
|
||||
|
||||
def read_submodules(repo, revision, label):
|
||||
if read_blob(repo, revision, ".gitmodules", label) is None:
|
||||
return {}
|
||||
try:
|
||||
output = git("config", "--null", "--blob", f"{revision}:.gitmodules", "--list", cwd=repo)
|
||||
except subprocess.CalledProcessError:
|
||||
raise ValueError(f"{label}: invalid .gitmodules") from None
|
||||
config = {}
|
||||
for record in output.split("\0"):
|
||||
if record:
|
||||
key, value = record.split("\n", 1)
|
||||
require(key not in config, f"{label}: duplicate submodule setting: {key}")
|
||||
config[key] = value
|
||||
return config
|
||||
|
||||
|
||||
def check_submodules(config, linked, depth, label, urls):
|
||||
"""Match ``.gitmodules`` sections by ``path``, not by section name.
|
||||
|
||||
Git configuration keys are keyed by the submodule section name, which is
|
||||
not required to equal the checked-out path. Path and URL remain the
|
||||
authority for identity; any other setting (for example an ``update``
|
||||
command or a relative override) is rejected as unexpected.
|
||||
"""
|
||||
sections = {}
|
||||
extras = []
|
||||
for key, value in config.items():
|
||||
match = re.fullmatch(r"submodule\.(.+)\.(path|url)", key)
|
||||
if not match:
|
||||
extras.append(key)
|
||||
continue
|
||||
name, field = match.groups()
|
||||
sections.setdefault(name, {})[field] = value
|
||||
by_path = {}
|
||||
for name, fields in sections.items():
|
||||
require(set(fields) == {"path", "url"},
|
||||
f"{label}: unexpected submodule settings: "
|
||||
f"{sorted(f'submodule.{name}.{field}' for field in set(fields) ^ {'path', 'url'})}")
|
||||
path = fields["path"]
|
||||
require(path not in by_path, f"{label}: duplicate submodule path: {path}")
|
||||
by_path[path] = fields["url"]
|
||||
require(not extras, f"{label}: unexpected submodule settings: {sorted(extras)}")
|
||||
for path, component in linked.items():
|
||||
require(path in by_path, f"{label}: missing or invalid submodule path: {path}")
|
||||
url = by_path.pop(path)
|
||||
expected = expected_remote(component, depth)
|
||||
require(url == expected, f"{label}: invalid submodule URL: {path}: {url!r}")
|
||||
require(url not in urls, f"{label}: duplicate submodule remote: {path}: {url}")
|
||||
urls[url] = path
|
||||
require(not by_path, f"{label}: unexpected submodule settings: {sorted(by_path)}")
|
||||
|
||||
|
||||
def read_layer(repo, revision, label, depth):
|
||||
repo = Path(repo)
|
||||
order = []
|
||||
components = {}
|
||||
paths = set()
|
||||
path_keys = set()
|
||||
for raw in parse_catalog(repo, revision, label):
|
||||
order.append(check_component(raw, depth, label, components, paths, path_keys))
|
||||
entries = tree_entries(repo, revision, label)
|
||||
gitlinks = {path: sha for path, (mode, sha) in entries.items() if mode == "160000"}
|
||||
active_paths = {item["path"] for item in order if item["state"] == "active"}
|
||||
mismatch = (active_paths - gitlinks.keys()) | (gitlinks.keys() - paths)
|
||||
require(not mismatch, f"{label}: gitlink/catalog mismatch: {sorted(mismatch)}")
|
||||
linked = {item["path"]: item for item in order if item["path"] in gitlinks}
|
||||
unlinked = [item for item in order if item["path"] not in gitlinks]
|
||||
if depth == 0:
|
||||
check_root_tree(entries, linked, unlinked, label)
|
||||
else:
|
||||
check_domain_tree(entries, linked, unlinked, label)
|
||||
urls = {}
|
||||
check_submodules(read_submodules(repo, revision, label), linked, depth, label, urls)
|
||||
return Layer(repo, revision, label, depth, order, components, gitlinks, linked, urls)
|
||||
|
||||
|
||||
def verify_checkout(layer, component):
|
||||
path = component["path"]
|
||||
checkout = layer.repo / path
|
||||
sha = layer.gitlinks[path]
|
||||
require(checkout.resolve() == checkout and (checkout / ".git").exists(),
|
||||
f"{layer.label}: missing submodule checkout: {path}")
|
||||
try:
|
||||
git("cat-file", "-e", f"{sha}^{{commit}}", cwd=checkout)
|
||||
except subprocess.CalledProcessError:
|
||||
raise ValueError(f"{layer.label}: missing committed object: {path}@{sha}") from None
|
||||
require(git("rev-parse", "HEAD", cwd=checkout).strip() == sha,
|
||||
f"{layer.label}: wrong checked-out commit: {path}")
|
||||
status = ["status", "--porcelain"]
|
||||
if component["kind"] == "domain":
|
||||
# Child dirt is the responsibility of the child checkout and is
|
||||
# reported by its own leaf check, not by the aggregate repository.
|
||||
status.append("--ignore-submodules=all")
|
||||
require(not git(*status, cwd=checkout),
|
||||
f"{layer.label}: dirty submodule: {path}")
|
||||
if component["state"] == "active":
|
||||
entry = checkout / component["entry"]
|
||||
require(entry.is_file() and entry.resolve() == entry,
|
||||
f"{layer.label}: missing or symbolic entry: {path}/{component['entry']}")
|
||||
return checkout
|
||||
|
||||
|
||||
def verify_leaf(layer, component):
|
||||
checkout = verify_checkout(layer, component)
|
||||
sha = layer.gitlinks[component["path"]]
|
||||
label = f'{layer.label} leaf {component["id"]} ({component["path"]})'
|
||||
nested = tree_entries(checkout, sha, label)
|
||||
gitlinks = sorted(path for path, (mode, _) in nested.items() if mode == "160000")
|
||||
require(not gitlinks, f"{label}: leaf must not register gitlinks: {gitlinks}")
|
||||
|
||||
|
||||
def validate_graph(layers):
|
||||
components = {}
|
||||
for layer in layers:
|
||||
for component in layer.order:
|
||||
id = component["id"]
|
||||
require(id not in components, f"{layer.label}: duplicate global id: {id}")
|
||||
components[id] = (component, layer)
|
||||
remotes = {}
|
||||
for layer in layers:
|
||||
for url, path in layer.urls.items():
|
||||
require(url not in remotes, f"{layer.label}: duplicate global remote: {path}: {url}")
|
||||
remotes[url] = path
|
||||
for layer in layers:
|
||||
for component in layer.order:
|
||||
id = component["id"]
|
||||
for field in ("requires", "checks_with"):
|
||||
for dependency in component[field]:
|
||||
require(dependency in components, f"{layer.label}: unknown dependency: {id} -> {dependency}")
|
||||
target, _ = components[dependency]
|
||||
require(component["state"] != "active" or target["state"] == "active",
|
||||
f"{layer.label}: active depends on planned: {id} -> {dependency}")
|
||||
if field != "requires":
|
||||
continue
|
||||
target_kind = target["kind"]
|
||||
source_kind = component["kind"]
|
||||
require(target_kind != "domain",
|
||||
f"{layer.label}: requires must not target a domain: {id} -> {dependency}")
|
||||
if source_kind in {"core", "domain"}:
|
||||
require(False, f"{layer.label}: dependency violation: {id} must not require {dependency}")
|
||||
if source_kind == "stdlib":
|
||||
require(target_kind in {"core", "stdlib"},
|
||||
f"{layer.label}: stdlib dependency violation: {id} -> {dependency}")
|
||||
elif source_kind == "tool":
|
||||
require(target_kind in {"core", "extension"},
|
||||
f"{layer.label}: tool dependency violation: {id} -> {dependency}")
|
||||
elif source_kind == "extension":
|
||||
require(target_kind in {"core", "stdlib", "extension"},
|
||||
f"{layer.label}: extension dependency violation: {id} -> {dependency}")
|
||||
try:
|
||||
graph = {id: list(item["requires"]) for id, (item, _) in components.items()}
|
||||
tuple(graphlib.TopologicalSorter(graph).static_order())
|
||||
except graphlib.CycleError as error:
|
||||
raise ValueError(f"root: requires DAG cycle: {error}") from None
|
||||
|
||||
|
||||
def validate(revision, checkouts, expand_domains=False):
|
||||
layers = [read_layer(ROOT, revision, "root", 0)]
|
||||
if checkouts or expand_domains:
|
||||
root = layers[0]
|
||||
for path, component in root.linked.items():
|
||||
if component["kind"] != "domain":
|
||||
if checkouts:
|
||||
verify_leaf(root, component)
|
||||
continue
|
||||
domain_repo = verify_checkout(root, component)
|
||||
domain = read_layer(domain_repo, root.gitlinks[path],
|
||||
f"domain {component['id']} ({path})", 1)
|
||||
layers.append(domain)
|
||||
if checkouts:
|
||||
for child in domain.linked.values():
|
||||
verify_leaf(domain, child)
|
||||
validate_graph(layers)
|
||||
return layers
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Validate a Marqdo ecosystem Git tree")
|
||||
parser.add_argument("revision", nargs="?", default="HEAD")
|
||||
parser.add_argument("--checkouts", action="store_true")
|
||||
paths = parser.add_mutually_exclusive_group()
|
||||
paths.add_argument("--active-paths", action="store_true", help="print only direct active component paths")
|
||||
paths.add_argument("--domain-paths", action="store_true", help="validate domain URLs and print domain paths")
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
revision = git("rev-parse", "--verify", args.revision + "^{commit}").strip()
|
||||
layers = validate(revision, args.checkouts, expand_domains=args.domain_paths)
|
||||
if args.active_paths:
|
||||
for path, component in sorted(layers[0].linked.items()):
|
||||
if component["state"] == "active":
|
||||
print(path)
|
||||
elif args.domain_paths:
|
||||
for path, component in sorted(layers[0].linked.items()):
|
||||
if component["kind"] == "domain":
|
||||
print(path)
|
||||
else:
|
||||
for layer in layers:
|
||||
for path, component in sorted(layer.linked.items()):
|
||||
relative = (layer.repo / path).relative_to(ROOT).as_posix()
|
||||
print(f'{component["id"]} {relative} {layer.gitlinks[path]} {component["state"]}')
|
||||
except (AttributeError, KeyError, OSError, subprocess.CalledProcessError, TypeError, ValueError) as error:
|
||||
sys.exit(f"layout: {error}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,423 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Recursive impact analysis between an accepted root commit and a candidate.
|
||||
|
||||
Compares the recursively expanded governance tree of two root revisions. A
|
||||
component identity is `(global_id, parent, remote, SHA, state)`; a domain
|
||||
gitlink change is expanded to its child identities so leaf changes are visible
|
||||
even when the parent pointer did not change as a string.
|
||||
|
||||
The affected set is computed in the order the development contract requires:
|
||||
|
||||
1. changed or removed leaves;
|
||||
2. reverse transitive closure over `requires` edges from the union of both
|
||||
graphs (removed edges cannot hide a consumer);
|
||||
3. parent domains of affected components;
|
||||
4. `checks_with` fixed point (co-validation is not a build prerequisite).
|
||||
|
||||
When a domain cannot be expanded (missing object/checkout) the result is marked
|
||||
UNVERIFIED and the whole domain is treated as affected rather than silently
|
||||
skipping it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SCHEMA = "marqdo.impact"
|
||||
SCHEMA_VERSION = 1
|
||||
|
||||
|
||||
class ImpactError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def git(repo: Path, *args: str) -> bytes:
|
||||
result = subprocess.run(["git", "-C", str(repo), *args], capture_output=True)
|
||||
if result.returncode != 0:
|
||||
raise ImpactError(
|
||||
f"git {' '.join(args)} failed in {repo}: "
|
||||
f"{result.stderr.decode(errors='replace').strip()}"
|
||||
)
|
||||
return result.stdout
|
||||
|
||||
|
||||
def show(repo: Path, revision: str, path: str) -> bytes | None:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(repo), "show", f"{revision}:{path}"], capture_output=True
|
||||
)
|
||||
return result.stdout if result.returncode == 0 else None
|
||||
|
||||
|
||||
def resolve(repo: Path, revision: str) -> str:
|
||||
try:
|
||||
return (
|
||||
git(repo, "rev-parse", "--verify", revision + "^{commit}")
|
||||
.decode()
|
||||
.strip()
|
||||
)
|
||||
except ImpactError as error:
|
||||
raise ImpactError(f"cannot resolve revision {revision!r}: {error}") from error
|
||||
|
||||
|
||||
def tree_entries(repo: Path, revision: str) -> dict[str, tuple[str, str]]:
|
||||
output = git(repo, "ls-tree", "-r", "-z", revision)
|
||||
entries: dict[str, tuple[str, str]] = {}
|
||||
for record in output.split(b"\0"):
|
||||
if not record:
|
||||
continue
|
||||
header, _, raw_path = record.partition(b"\t")
|
||||
fields = header.decode().split()
|
||||
if len(fields) != 3:
|
||||
raise ImpactError(f"invalid tree record in {repo}@{revision}")
|
||||
mode, _kind, sha = fields
|
||||
entries[raw_path.decode()] = (mode, sha)
|
||||
return entries
|
||||
|
||||
|
||||
def submodule_urls(repo: Path, revision: str) -> dict[str, str]:
|
||||
"""Map `.gitmodules` path to URL at a revision (authority for remotes)."""
|
||||
raw = show(repo, revision, ".gitmodules")
|
||||
if raw is None:
|
||||
return {}
|
||||
config = git(
|
||||
repo, "config", "--null", "--blob", f"{revision}:.gitmodules", "--list"
|
||||
)
|
||||
urls: dict[str, str] = {}
|
||||
pending: dict[str, dict[str, str]] = {}
|
||||
for record in config.split(b"\0"):
|
||||
if not record:
|
||||
continue
|
||||
key, _, value = record.decode(errors="replace").partition("\n")
|
||||
match = re.fullmatch(r"submodule\.(.+)\.(path|url)", key)
|
||||
if match:
|
||||
name, field = match.groups()
|
||||
pending.setdefault(name, {})[field] = value
|
||||
for fields in pending.values():
|
||||
if "path" in fields and "url" in fields:
|
||||
urls[fields["path"]] = fields["url"]
|
||||
return urls
|
||||
|
||||
|
||||
def read_catalog(repo: Path, revision: str, label: str) -> list[dict]:
|
||||
raw = show(repo, revision, "components.toml")
|
||||
if raw is None:
|
||||
raise ImpactError(f"{label}: revision {revision} has no components.toml")
|
||||
try:
|
||||
catalog = tomllib.loads(raw.decode())
|
||||
except (UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
|
||||
raise ImpactError(f"{label}: invalid components.toml: {error}") from error
|
||||
components = catalog.get("component")
|
||||
if not isinstance(components, list):
|
||||
raise ImpactError(f"{label}: components.toml has no [[component]] entries")
|
||||
return components
|
||||
|
||||
|
||||
def load_graph(
|
||||
repo: Path, revision: str, label: str, depth: int = 0
|
||||
) -> tuple[dict[str, dict], list[str]]:
|
||||
"""Expand one governance layer (root then domains) into global identities."""
|
||||
components = read_catalog(repo, revision, label)
|
||||
entries = tree_entries(repo, revision)
|
||||
urls = submodule_urls(repo, revision)
|
||||
gitlinks = {path: sha for path, (mode, sha) in entries.items() if mode == "160000"}
|
||||
graph: dict[str, dict] = {}
|
||||
unverified: list[str] = []
|
||||
for component in components:
|
||||
component_id = component.get("id")
|
||||
path = component.get("path")
|
||||
if not isinstance(component_id, str) or not isinstance(path, str):
|
||||
raise ImpactError(f"{label}: component without id/path")
|
||||
sha = gitlinks.get(path)
|
||||
identity = {
|
||||
"id": component_id,
|
||||
"parent": None,
|
||||
"path": path,
|
||||
"remote": urls.get(path),
|
||||
"sha": sha,
|
||||
"state": component.get("state"),
|
||||
"kind": component.get("kind"),
|
||||
"requires": sorted(component.get("requires", [])),
|
||||
"checks_with": sorted(component.get("checks_with", [])),
|
||||
"layer": label,
|
||||
}
|
||||
graph[component_id] = identity
|
||||
if component.get("kind") != "domain" or depth > 0:
|
||||
continue
|
||||
domain_repo = repo / path
|
||||
if sha is None or not (domain_repo / ".git").exists():
|
||||
unverified.append(
|
||||
f"{label}: domain {component_id} ({path}) cannot be expanded: "
|
||||
"missing gitlink or checkout"
|
||||
)
|
||||
continue
|
||||
try:
|
||||
children, child_unverified = load_graph(
|
||||
domain_repo, sha, f"domain {component_id}", depth + 1
|
||||
)
|
||||
except ImpactError as error:
|
||||
unverified.append(
|
||||
f"{label}: domain {component_id} ({path})@{sha} cannot be expanded: {error}"
|
||||
)
|
||||
continue
|
||||
unverified.extend(child_unverified)
|
||||
for child_id, child in children.items():
|
||||
if child_id in graph:
|
||||
raise ImpactError(f"{label}: duplicate global id {child_id}")
|
||||
child["parent"] = component_id
|
||||
graph[child_id] = child
|
||||
return graph, unverified
|
||||
|
||||
|
||||
def identity_fields(component: dict) -> tuple:
|
||||
return (
|
||||
component.get("parent"),
|
||||
component.get("remote"),
|
||||
component.get("sha"),
|
||||
component.get("state"),
|
||||
tuple(component.get("requires", [])),
|
||||
tuple(component.get("checks_with", [])),
|
||||
)
|
||||
|
||||
|
||||
def changed_components(
|
||||
accepted: dict[str, dict], candidate: dict[str, dict]
|
||||
) -> list[dict]:
|
||||
changed = []
|
||||
for component_id in sorted(set(accepted) | set(candidate)):
|
||||
before = accepted.get(component_id)
|
||||
after = candidate.get(component_id)
|
||||
if before is None:
|
||||
changed.append({"id": component_id, "reason": "added"})
|
||||
continue
|
||||
if after is None:
|
||||
changed.append({"id": component_id, "reason": "removed"})
|
||||
continue
|
||||
if before.get("sha") != after.get("sha"):
|
||||
changed.append({"id": component_id, "reason": "sha"})
|
||||
elif before.get("state") != after.get("state"):
|
||||
changed.append({"id": component_id, "reason": "state"})
|
||||
elif before.get("remote") != after.get("remote"):
|
||||
changed.append({"id": component_id, "reason": "remote"})
|
||||
elif before.get("parent") != after.get("parent"):
|
||||
changed.append({"id": component_id, "reason": "parent"})
|
||||
elif before.get("requires") != after.get("requires") or before.get(
|
||||
"checks_with"
|
||||
) != after.get("checks_with"):
|
||||
changed.append({"id": component_id, "reason": "dependencies"})
|
||||
return changed
|
||||
|
||||
|
||||
def affected_set(
|
||||
accepted: dict[str, dict], candidate: dict[str, dict], changed: list[dict]
|
||||
) -> tuple[list[str], list[str], list[str]]:
|
||||
graph = {**accepted, **candidate}
|
||||
dependents: dict[str, set[str]] = {component_id: set() for component_id in graph}
|
||||
for component in graph.values():
|
||||
for dependency in component.get("requires", []):
|
||||
dependents.setdefault(dependency, set()).add(component["id"])
|
||||
affected = {item["id"] for item in changed}
|
||||
queue = list(affected)
|
||||
while queue:
|
||||
current = queue.pop()
|
||||
for consumer in dependents.get(current, set()):
|
||||
if consumer not in affected:
|
||||
affected.add(consumer)
|
||||
queue.append(consumer)
|
||||
domains = set()
|
||||
for component_id in list(affected):
|
||||
parent = graph[component_id].get("parent")
|
||||
while parent:
|
||||
if parent not in affected:
|
||||
domains.add(parent)
|
||||
parent = graph[parent].get("parent") if parent in graph else None
|
||||
co_validation: set[str] = set()
|
||||
while True:
|
||||
additions = set()
|
||||
for component_id in affected:
|
||||
for partner in graph[component_id].get("checks_with", []):
|
||||
if partner not in affected:
|
||||
additions.add(partner)
|
||||
if not additions:
|
||||
break
|
||||
affected |= additions
|
||||
co_validation |= additions
|
||||
return sorted(affected), sorted(domains), sorted(co_validation)
|
||||
|
||||
|
||||
def consumers_of(component_id: str, revision: str) -> dict:
|
||||
"""Consumers of one component at a revision (component-PR impact scope).
|
||||
|
||||
Uses the accepted graph only: a component candidate cannot change the root
|
||||
graph it is evaluated against. Unknown component or unexpandable domain
|
||||
widens the scope to the whole graph (never silently skip).
|
||||
"""
|
||||
revision_sha = resolve(ROOT, revision)
|
||||
graph, unverified = load_graph(ROOT, revision_sha, "root")
|
||||
if component_id not in graph:
|
||||
graph, unverified = load_graph(ROOT, revision_sha, "root")
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"accepted": {"ref": revision, "revision": revision_sha},
|
||||
"component": component_id,
|
||||
"affected": sorted(graph),
|
||||
"checks_with": [],
|
||||
"domain_ancestors": [],
|
||||
"fallback": "full",
|
||||
"unverified": unverified
|
||||
+ [f"unknown component {component_id!r} at {revision_sha}; scope widened"],
|
||||
}
|
||||
dependents: dict[str, set[str]] = {key: set() for key in graph}
|
||||
for component in graph.values():
|
||||
for dependency in component.get("requires", []):
|
||||
dependents.setdefault(dependency, set()).add(component["id"])
|
||||
affected = {component_id}
|
||||
queue = [component_id]
|
||||
while queue:
|
||||
current = queue.pop()
|
||||
for consumer in dependents.get(current, set()):
|
||||
if consumer not in affected:
|
||||
affected.add(consumer)
|
||||
queue.append(consumer)
|
||||
domains = set()
|
||||
for item in list(affected):
|
||||
parent = graph[item].get("parent")
|
||||
while parent:
|
||||
if parent not in affected:
|
||||
domains.add(parent)
|
||||
parent = graph[parent].get("parent") if parent in graph else None
|
||||
co_validation: set[str] = set()
|
||||
while True:
|
||||
additions = {
|
||||
partner
|
||||
for item in affected
|
||||
for partner in graph[item].get("checks_with", [])
|
||||
if partner not in affected
|
||||
}
|
||||
if not additions:
|
||||
break
|
||||
affected |= additions
|
||||
co_validation |= additions
|
||||
fallback = None
|
||||
if unverified:
|
||||
affected = set(graph)
|
||||
domains = set()
|
||||
co_validation = set()
|
||||
fallback = "full"
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"accepted": {"ref": revision, "revision": revision_sha},
|
||||
"component": component_id,
|
||||
"affected": sorted(affected),
|
||||
"checks_with": sorted(co_validation),
|
||||
"domain_ancestors": sorted(domains),
|
||||
"fallback": fallback,
|
||||
"unverified": unverified,
|
||||
}
|
||||
|
||||
|
||||
def analyze(accepted_ref: str, candidate_ref: str) -> dict:
|
||||
accepted_revision = resolve(ROOT, accepted_ref)
|
||||
candidate_revision = resolve(ROOT, candidate_ref)
|
||||
accepted, accepted_unverified = load_graph(ROOT, accepted_revision, "root")
|
||||
candidate, candidate_unverified = load_graph(ROOT, candidate_revision, "root")
|
||||
changed = changed_components(accepted, candidate)
|
||||
affected, domains, co_validation = affected_set(accepted, candidate, changed)
|
||||
unverified = accepted_unverified + candidate_unverified
|
||||
fallback = None
|
||||
if unverified:
|
||||
# Undetermined scope must widen, never silently skip.
|
||||
affected = sorted(set(accepted) | set(candidate))
|
||||
domains = []
|
||||
co_validation = []
|
||||
fallback = "full"
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"accepted": {"ref": accepted_ref, "revision": accepted_revision},
|
||||
"candidate": {"ref": candidate_ref, "revision": candidate_revision},
|
||||
"counts": {
|
||||
"accepted_components": len(accepted),
|
||||
"candidate_components": len(candidate),
|
||||
"changed": len(changed),
|
||||
"affected": len(affected),
|
||||
},
|
||||
"changed": changed,
|
||||
"affected": affected,
|
||||
"domain_ancestors": domains,
|
||||
"checks_with": co_validation,
|
||||
"fallback": fallback,
|
||||
"unverified": unverified,
|
||||
}
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--accepted", required=True, help="accepted root revision")
|
||||
parser.add_argument("--candidate", default="HEAD", help="candidate root revision")
|
||||
parser.add_argument("--out", default=None)
|
||||
parser.add_argument("--json", action="store_true")
|
||||
parser.add_argument(
|
||||
"--component",
|
||||
default=None,
|
||||
help="report consumers of one component at --accepted instead of a root diff",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--fail-on-unverified",
|
||||
action="store_true",
|
||||
help="exit 2 when a domain cannot be expanded",
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
if args.component:
|
||||
report = consumers_of(args.component, args.accepted)
|
||||
else:
|
||||
report = analyze(args.accepted, args.candidate)
|
||||
except ImpactError as error:
|
||||
print(f"impact: error: {error}", file=sys.stderr)
|
||||
return 1
|
||||
text = json.dumps(report, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.out:
|
||||
Path(args.out).write_text(text)
|
||||
if args.json:
|
||||
print(text, end="")
|
||||
else:
|
||||
if "candidate" in report:
|
||||
print(
|
||||
f"accepted {report['accepted']['revision'][:12]} "
|
||||
f"candidate {report['candidate']['revision'][:12]}"
|
||||
)
|
||||
print(
|
||||
f"changed={report['counts']['changed']} "
|
||||
f"affected={report['counts']['affected']}"
|
||||
)
|
||||
for item in report["changed"]:
|
||||
print(f" changed {item['id']}: {item['reason']}")
|
||||
else:
|
||||
print(
|
||||
f"component {report['component']} at "
|
||||
f"{report['accepted']['revision'][:12]}"
|
||||
)
|
||||
print(f"consumers={len(report['affected'])}")
|
||||
print("affected: " + ", ".join(report["affected"]))
|
||||
if report["checks_with"]:
|
||||
print("co-validation: " + ", ".join(report["checks_with"]))
|
||||
if report["fallback"]:
|
||||
print("fallback: full (impact scope undetermined)")
|
||||
for note in report["unverified"]:
|
||||
print(f"UNVERIFIED: {note}", file=sys.stderr)
|
||||
if args.fail_on_unverified and report["unverified"]:
|
||||
return 2
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
@@ -1,188 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Ecosystem integration for one exact candidate combination.
|
||||
#
|
||||
# Inputs are the pinned root gitlinks: the root-owned Bundle producer assembles
|
||||
# the one stdlib Bundle, the CLI/Worker are built from the pinned `cli` commit,
|
||||
# the release archive is packaged with that explicit Bundle, and every consumer
|
||||
# runs against that same installed binary + adjacent Bundle. There is no
|
||||
# implicit artifact from View, no floating branch and no network-selected CLI.
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
root="$PWD"
|
||||
active="$(python3 scripts/check-layout.py --checkouts --active-paths)"
|
||||
expected=$'cli\nstdlib/collections\nstdlib/data\nstdlib/fs\nstdlib/io\nstdlib/system\nstdlib/text\ntests/conformance\ntools/knowledge\ntools/lint\ntools/prove\ntools/view'
|
||||
if [[ "$active" != "$expected" ]]; then
|
||||
echo "UNVERIFIED: update the integration plan for the changed active component set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p .integration-work
|
||||
work="$(mktemp -d "$root/.integration-work/run.XXXXXX")"
|
||||
echo "integration evidence: $work"
|
||||
exec > >(tee "$work/run.log") 2>&1
|
||||
set -x
|
||||
|
||||
git rev-parse HEAD
|
||||
git submodule status --recursive
|
||||
uname -m
|
||||
ldd --version
|
||||
cargo --version
|
||||
python3 --version
|
||||
python3 -c 'import jsonschema'
|
||||
python3 scripts/check-layout.py --checkouts > "$work/layout.txt"
|
||||
cat "$work/layout.txt"
|
||||
|
||||
# Recursive impact analysis against the accepted root commit: the change set
|
||||
# comes from the recursively expanded (global_id, parent, remote, SHA, state)
|
||||
# identities, then reverse `requires` closure, parent domains and `checks_with`
|
||||
# fixed point. An undetermined scope widens to the full candidate.
|
||||
accepted_ref="${MARQDO_ACCEPTED_REF:-}"
|
||||
if [[ -z "$accepted_ref" && -n "${CI_COMMIT_TARGET_BRANCH:-}" ]] \
|
||||
&& git rev-parse --verify "origin/$CI_COMMIT_TARGET_BRANCH" >/dev/null 2>&1; then
|
||||
accepted_ref="origin/$CI_COMMIT_TARGET_BRANCH"
|
||||
elif [[ -z "$accepted_ref" ]] && git rev-parse --verify origin/main >/dev/null 2>&1; then
|
||||
accepted_ref="origin/main"
|
||||
fi
|
||||
if [[ -n "$accepted_ref" ]]; then
|
||||
python3 scripts/impact.py --accepted "$accepted_ref" --candidate HEAD \
|
||||
--out "$work/impact.json"
|
||||
fi
|
||||
|
||||
# 1. One Bundle, produced by the root-owned producer from the pinned gitlinks.
|
||||
python3 scripts/build-stdlib.py --out "$work/stdlib" | tee "$work/bundle.json"
|
||||
bundle_digest="$(python3 -c 'import json,sys; print(json.load(sys.stdin)["tree_digest"])' < "$work/bundle.json")"
|
||||
bundle_aliases="$(python3 -c 'import json,sys; print(json.load(sys.stdin)["aliases_digest"])' < "$work/bundle.json")"
|
||||
test -f "$work/stdlib/stdlib.json"
|
||||
|
||||
# 2. CLI and Worker from the exact pinned CLI gitlink.
|
||||
source_sha="$(git -C cli rev-parse HEAD)"
|
||||
# The CLI release packager resolves its binaries from the pinned CLI checkout's
|
||||
# own target directory; keep this build there so the package step consumes the
|
||||
# same artifacts without a second build. Do not export CARGO_TARGET_DIR: the
|
||||
# consumer repositories build into their own target directories.
|
||||
CARGO_TARGET_DIR="$root/cli/target" \
|
||||
cargo build --manifest-path cli/Cargo.toml --locked --release \
|
||||
-p marqdo-cli -p marqdo-provider-worker
|
||||
version="$(python3 -c '
|
||||
import pathlib, tomllib
|
||||
data = tomllib.loads(pathlib.Path("cli/Cargo.toml").read_text())
|
||||
print(data["workspace"]["package"]["version"])
|
||||
')"
|
||||
|
||||
# 3. The release archive takes the Bundle as one explicit input.
|
||||
python3 cli/tools/release/package.py \
|
||||
--source-sha "$source_sha" --version "$version" \
|
||||
--stdlib-dir "$work/stdlib" --out-dir "$work/dist" | tee "$work/package.json"
|
||||
archive="$(find "$work/dist" -maxdepth 1 -name 'marqdo-*.tar.gz' -print -quit)"
|
||||
python3 cli/tools/release/smoke.py --archive "$archive"
|
||||
mkdir -p "$work/install"
|
||||
tar -xzf "$archive" -C "$work/install"
|
||||
installed="$(find "$work/install" -mindepth 1 -maxdepth 1 -type d -print -quit)"
|
||||
MARQDO_BIN="$installed/marqdo"
|
||||
export MARQDO_BIN
|
||||
test "$(cat "$installed/SOURCE_SHA")" = "$source_sha"
|
||||
test "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$installed/stdlib/stdlib.json")" = "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$work/stdlib/stdlib.json")"
|
||||
sha256sum "$archive" "$MARQDO_BIN" "$installed/marqdo-provider-worker"
|
||||
|
||||
# 4. Root stdlib acceptance: component entries, explicit Packages, composition
|
||||
# fixtures and fail-closed negatives with the same installed CLI/Bundle.
|
||||
python3 scripts/acceptance-stdlib.py \
|
||||
--cli "$MARQDO_BIN" --bundle "$work/stdlib" \
|
||||
--work "$work/stdlib-acceptance" --evidence "$work/stdlib-acceptance.json"
|
||||
|
||||
# 5. Frozen independent public-contract fixtures against the same CLI.
|
||||
python3 cli/tools/ci/verify_extension_contracts.py \
|
||||
--source-repo cli --tested-sha "$source_sha" --cli "$MARQDO_BIN" \
|
||||
--release-info "$installed/RELEASE_INFO.json" \
|
||||
--fixtures tests/conformance --out "$work/conformance.json"
|
||||
|
||||
# 6. Existing consumers, same installed binary and adjacent Bundle.
|
||||
(
|
||||
cd tools/view
|
||||
export MARQDO_TOOL_HOME="$work/view-registry"
|
||||
scripts/package.sh
|
||||
"$MARQDO_BIN" tool install dist/marqdo-view/tool.json
|
||||
"$MARQDO_BIN" view verify examples/mixed-modes/index.mq.md
|
||||
"$MARQDO_BIN" view export examples/tables-math --out "$work/view-export"
|
||||
setsid "$MARQDO_BIN" view examples/control-flow --port 0 --no-open >"$work/view-server.log" 2>&1 &
|
||||
view_pid=$!
|
||||
stop_view() {
|
||||
kill -- "-$view_pid" 2>/dev/null || true
|
||||
wait "$view_pid" 2>/dev/null || true
|
||||
}
|
||||
trap stop_view EXIT
|
||||
view_url=""
|
||||
for attempt in {1..100}; do
|
||||
view_url="$(grep -m1 -o 'http://127\.0\.0\.1:[0-9]\+/' "$work/view-server.log" || true)"
|
||||
if [[ -n "$view_url" ]] || ! kill -0 "$view_pid" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
if [[ -z "$view_url" ]]; then
|
||||
cat "$work/view-server.log" >&2
|
||||
exit 1
|
||||
fi
|
||||
python3 scripts/acceptance-run.py "$view_url"
|
||||
stop_view
|
||||
trap - EXIT
|
||||
python3 scripts/check-observation.py stream-snapshot
|
||||
"$MARQDO_BIN" tool remove view
|
||||
if "$MARQDO_BIN" view --version; then
|
||||
echo "view still dispatches after removal" >&2
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
(
|
||||
cd tools/knowledge
|
||||
MARQDO_TEST_BIN="$MARQDO_BIN" cargo test --locked --test core_cli --test compile
|
||||
)
|
||||
(
|
||||
cd tools/prove
|
||||
cargo test --locked --test analysis_document --test document_contract
|
||||
)
|
||||
(
|
||||
cd tools/lint
|
||||
export MARQDO_TOOL_HOME="$work/lint-registry"
|
||||
scripts/package-tool.sh "$work/lint"
|
||||
"$MARQDO_BIN" tool install "$work/lint/tool.json"
|
||||
"$MARQDO_BIN" lint examples/nested/inventory.mq.md --format json
|
||||
"$MARQDO_BIN" tool remove lint
|
||||
)
|
||||
|
||||
# 7. Evidence identity for the accepted candidate.
|
||||
root_commit="$(git rev-parse HEAD)"
|
||||
python3 - "$work" "$root_commit" "$source_sha" "$bundle_digest" "$bundle_aliases" "$archive" <<'PY'
|
||||
import hashlib, json, pathlib, sys
|
||||
work = pathlib.Path(sys.argv[1])
|
||||
archive = pathlib.Path(sys.argv[6])
|
||||
impact_path = work / "impact.json"
|
||||
impact = json.loads(impact_path.read_text()) if impact_path.is_file() else None
|
||||
evidence = {
|
||||
"schema": "marqdo.ecosystem-integration",
|
||||
"schema_version": 1,
|
||||
"root_commit": sys.argv[2],
|
||||
"cli_source_sha": sys.argv[3],
|
||||
"stdlib_tree_digest": sys.argv[4],
|
||||
"stdlib_aliases_digest": sys.argv[5],
|
||||
"archive": archive.name,
|
||||
"archive_sha256": "sha256:" + hashlib.sha256(archive.read_bytes()).hexdigest(),
|
||||
"impact": (
|
||||
{
|
||||
"changed": impact["changed"],
|
||||
"affected": impact["affected"],
|
||||
"checks_with": impact["checks_with"],
|
||||
"fallback": impact["fallback"],
|
||||
"unverified": impact["unverified"],
|
||||
}
|
||||
if impact
|
||||
else None
|
||||
),
|
||||
"status": "PASS",
|
||||
}
|
||||
(work / "integration-evidence.json").write_text(json.dumps(evidence, indent=2) + "\n")
|
||||
print(json.dumps(evidence, indent=2))
|
||||
PY
|
||||
|
||||
echo "PASS: ecosystem candidate (single CLI/Worker/Bundle artifact, consumers green)"
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"name": "marqdo-stdlib",
|
||||
"version": "0.2.0",
|
||||
"public_aliases": [
|
||||
{
|
||||
"public_names": ["print", "打印"],
|
||||
"target_module": "io.mq.md",
|
||||
"target_function": "写值",
|
||||
"expected_signature": "params(值)",
|
||||
"effects": ["host"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
title: 解释器源码的放置位置
|
||||
date: 2026-08-11
|
||||
---
|
||||
|
||||
## 这里放置解释器源码
|
||||
@@ -0,0 +1,40 @@
|
||||
//解释器检测到错误的处理模块
|
||||
|
||||
//! 错误报告模块,集中管理解释器所有语法错误输出
|
||||
// use std::io;
|
||||
// use std::io::Write;
|
||||
|
||||
//建立独立抽象ErrorReport结构体
|
||||
//错误报告器,保存错误状态并提供错误报告接口
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ErrorReport {
|
||||
had_error: bool,
|
||||
}
|
||||
|
||||
impl ErrorReport {
|
||||
//创建新的错误报告器
|
||||
pub fn new() -> Self {
|
||||
Self { had_error: false }
|
||||
}
|
||||
|
||||
//对外公开的错误接口,指定行号和错误信息
|
||||
pub fn error(&mut self, line: usize, message: &str) {
|
||||
self.report(line, "", message);
|
||||
}
|
||||
|
||||
//内部私有函数,输出错误信息,标记错误状态为true
|
||||
fn report(&mut self, line: usize, location: &str, message: &str) {
|
||||
eprintln!("[line {}] Error{}: {}", line, location, message);
|
||||
self.had_error = true;
|
||||
}
|
||||
|
||||
//获取错误状态
|
||||
pub fn has_error(&self) -> bool {
|
||||
self.had_error
|
||||
}
|
||||
|
||||
//重置错误状态
|
||||
pub fn clear(&mut self) {
|
||||
self.had_error = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//使用rust开发marqdo语言的解释器
|
||||
|
||||
//导入库
|
||||
use std::env; //用于获取命令行参数
|
||||
use std::fs; //用于读取文件
|
||||
// use std::io; //用于读取标准输入和输出
|
||||
// use std::io::BufReader; //用于读取缓冲区
|
||||
|
||||
//导入错误报告模块
|
||||
mod error;
|
||||
use error::ErrorReport;
|
||||
|
||||
fn main() {
|
||||
//创建新的错误报告器
|
||||
let mut error_report = ErrorReport::new();
|
||||
//获取命令行参数
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
//解析命令行参数
|
||||
if args.len() > 3 {
|
||||
eprintln!("Usage: marqdo <use_mode> <file>");
|
||||
std::process::exit(1);
|
||||
}
|
||||
else if args.len() == 3 {
|
||||
let use_mode = &args[1];
|
||||
let file_path = &args[2];
|
||||
//传入模式选择函数,根据不同的模式选择不同的函数执行
|
||||
mode_selector(use_mode, file_path, &mut error_report);
|
||||
}
|
||||
else if args.len() == 2 {
|
||||
let file_path = &args[1];
|
||||
//默认为run模式,自动进行文件执行
|
||||
run_file(file_path, &mut error_report);
|
||||
}
|
||||
else {
|
||||
//无参数输入,默认进入交互模式
|
||||
run_prompt(&mut error_report);
|
||||
}
|
||||
}
|
||||
|
||||
//模式选择函数
|
||||
fn mode_selector(use_mode: &str, file_path: &str, error_report: &mut ErrorReport) {
|
||||
//根据不同的模式选择不同的函数执行
|
||||
match use_mode {
|
||||
"run" => run_file(file_path, error_report),
|
||||
_ => {eprintln!("Invalid use mode: {}", use_mode);
|
||||
std::process::exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//读取marqdo文件并运行marqdo脚本文件
|
||||
fn run_file(file_path: &str, error_report: &mut ErrorReport) {
|
||||
match fs::read_to_string(file_path) {
|
||||
Ok(source) => {
|
||||
run(&source, error_report);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error reading file: {}", e);
|
||||
std::process::exit(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//交互式模式
|
||||
fn run_prompt(error_report: &mut ErrorReport) {
|
||||
//提示交互式模式正在开发中
|
||||
println!("Interactive mode is not available yet.");
|
||||
error_report.error(0, "Interactive mode is not available yet.");
|
||||
//清除错误报告
|
||||
error_report.clear();
|
||||
std::process::exit(4);
|
||||
}
|
||||
|
||||
//运行marqdo脚本
|
||||
fn run(source: &str, error_report: &mut ErrorReport) {
|
||||
//提示正在开发中
|
||||
println!("Running script is not available yet.");
|
||||
//输出source
|
||||
println!("Source: {}", source);
|
||||
//输出错误报告
|
||||
println!("Error report: {}", error_report.has_error());
|
||||
//退出程序
|
||||
std::process::exit(5);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
# 标准库
|
||||
|
||||
标准库组件负责低层通用能力,验收后共同组成基础发行的标准库 Bundle。各目录通过 Git 子模块固定独立标准库仓库的开发提交。
|
||||
|
||||
- [marqdo-std-core](https://git.cflmy.cn/cflmy/marqdo-std-core) · Result 与基础数值
|
||||
- [marqdo-std-collections](https://git.cflmy.cn/cflmy/marqdo-std-collections) · List、Map 和 Table 值操作
|
||||
- [marqdo-std-text](https://git.cflmy.cn/cflmy/marqdo-std-text) · Unicode 文本、字节值与 UTF-8
|
||||
- [marqdo-std-encoding](https://git.cflmy.cn/cflmy/marqdo-std-encoding) · Base64、Base32 和 Hex
|
||||
- [marqdo-std-data](https://git.cflmy.cn/cflmy/marqdo-std-data) · JSON、CSV、TOML 与 GFM 数据转换
|
||||
- [marqdo-std-io](https://git.cflmy.cn/cflmy/marqdo-std-io) · Console、Stream、格式化和官方 print 别名
|
||||
- [marqdo-std-fs](https://git.cflmy.cn/cflmy/marqdo-std-fs) · 文件、目录与路径
|
||||
- [marqdo-std-system](https://git.cflmy.cn/cflmy/marqdo-std-system) · 时钟、UTC、环境、进程与随机
|
||||
- [marqdo-std-net](https://git.cflmy.cn/cflmy/marqdo-std-net) · TCP、UDP、TLS 和网络字节流
|
||||
|
||||
[组件目录](../components.toml) · [各仓库任务](../docs/REPOSITORY-TASKS.md)
|
||||
Submodule stdlib/collections deleted from 4907652268.
-1
Submodule stdlib/core deleted from 997a970f9e.
-1
Submodule stdlib/data deleted from 848af7a357.
Submodule stdlib/encoding deleted from 1aab705e5b.
-1
Submodule stdlib/fs deleted from 63bceae587.
-1
Submodule stdlib/io deleted from e18b0b1b40.
-1
Submodule stdlib/net deleted from 8aad76d87f.
Submodule stdlib/system deleted from 053ddb0e59.
-1
Submodule stdlib/text deleted from c2a7d327e5.
@@ -0,0 +1,6 @@
|
||||
---
|
||||
title: marqdo语言测试用例的放置位置
|
||||
date: 2026-08-11
|
||||
---
|
||||
|
||||
## 这里用于放置marqdo语言的测试用例
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: hello marqdo!
|
||||
---
|
||||
|
||||
> print "hello marqdo!"
|
||||
Submodule tests/conformance deleted from 015ff8ac15.
@@ -1,9 +0,0 @@
|
||||
# @exec aliases
|
||||
|
||||
## main
|
||||
|
||||
> **打印("alias-打印")**
|
||||
|
||||
> **print("alias-print")**
|
||||
|
||||
`return None`
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"schema": "marqdo.stdlib-test-case",
|
||||
"schema_version": 1,
|
||||
"name": "aliases",
|
||||
"file": "aliases.mq.md",
|
||||
"args": [],
|
||||
"stdin": "",
|
||||
"env": {},
|
||||
"expected_stdout": "alias-打印\nalias-print\n",
|
||||
"expected_terminal": {
|
||||
"type": "none"
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
{
|
||||
"schema": "marqdo.stdlib-test-case",
|
||||
"schema_version": 1,
|
||||
"name": "default-bundle",
|
||||
"file": "default-bundle.mq.md",
|
||||
"args": [],
|
||||
"stdin": "",
|
||||
"env": {},
|
||||
"expected_stdout": "default-bundle\n",
|
||||
"expected_terminal": {
|
||||
"items": [
|
||||
{
|
||||
"decimal": "2",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"decimal": "195",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"decimal": "169",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "é"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "[\"ok\", 3]"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "[1, 2]"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "a/b/c"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "2026-11-21T08:00:00.123Z"
|
||||
},
|
||||
{
|
||||
"decimal": "2",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"schema": "marqdo.stdlib-test-case",
|
||||
"schema_version": 1,
|
||||
"name": "print-routing",
|
||||
"file": "print-routing.mq.md",
|
||||
"args": [],
|
||||
"stdin": "",
|
||||
"env": {},
|
||||
"expected_stdout": "[\"文本\", 2, 1.5, [3, true], {a: 1, b: \"x\"}, None]\n[\"文本\", 2, 1.5, [3, true], {a: 1, b: \"x\"}, None]\nTable[名称 | 分数]{甲 | 87; 乙 | 92}\nTable[名称 | 分数]{甲 | 87; 乙 | 92}\n[Formula(\"a = 1\"), Code(\"text\", 9 bytes), FunctionRef(root:default::print-routing.mq.md::演示函数)]\n[Formula(\"a = 1\"), Code(\"text\", 9 bytes), FunctionRef(root:default::print-routing.mq.md::演示函数)]\n",
|
||||
"expected_terminal": {
|
||||
"type": "none"
|
||||
},
|
||||
"stdout_line_pairs": [
|
||||
[
|
||||
0,
|
||||
1
|
||||
],
|
||||
[
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
{
|
||||
"schema": "marqdo.stdlib-test-case",
|
||||
"schema_version": 1,
|
||||
"name": "table-pure",
|
||||
"file": "table.mq.md",
|
||||
"args": [
|
||||
"--mode",
|
||||
"pure"
|
||||
],
|
||||
"stdin": "",
|
||||
"env": {},
|
||||
"expected_stdout": "",
|
||||
"expected_terminal": {
|
||||
"items": [
|
||||
{
|
||||
"header": [
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丁"
|
||||
},
|
||||
{
|
||||
"decimal": "65",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "99",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数",
|
||||
"名称",
|
||||
"等级"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "B"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "A"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"entries": {
|
||||
"a": {
|
||||
"items": [
|
||||
{
|
||||
"decimal": "1",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"decimal": "3",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
},
|
||||
"b": {
|
||||
"items": [
|
||||
{
|
||||
"decimal": "2",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
}
|
||||
},
|
||||
"type": "map"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "| 名称 | 分数 |\n| --- | --- |\n| 甲 | 87 |\n| 乙 | 92 |\n| 丙 | 71 |"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
}
|
||||
}
|
||||
@@ -1,314 +0,0 @@
|
||||
{
|
||||
"schema": "marqdo.stdlib-test-case",
|
||||
"schema_version": 1,
|
||||
"name": "table",
|
||||
"file": "table.mq.md",
|
||||
"args": [],
|
||||
"stdin": "",
|
||||
"env": {},
|
||||
"expected_stdout": "",
|
||||
"expected_terminal": {
|
||||
"items": [
|
||||
{
|
||||
"header": [
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丁"
|
||||
},
|
||||
{
|
||||
"decimal": "65",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "99",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数",
|
||||
"名称",
|
||||
"等级"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "B"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "A"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"entries": {
|
||||
"a": {
|
||||
"items": [
|
||||
{
|
||||
"decimal": "1",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"decimal": "3",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
},
|
||||
"b": {
|
||||
"items": [
|
||||
{
|
||||
"decimal": "2",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
}
|
||||
},
|
||||
"type": "map"
|
||||
},
|
||||
{
|
||||
"header": [
|
||||
"名称",
|
||||
"分数"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "甲"
|
||||
},
|
||||
{
|
||||
"decimal": "87",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "乙"
|
||||
},
|
||||
{
|
||||
"decimal": "92",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "text",
|
||||
"value": "丙"
|
||||
},
|
||||
{
|
||||
"decimal": "71",
|
||||
"type": "int"
|
||||
}
|
||||
]
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "| 名称 | 分数 |\n| --- | --- |\n| 甲 | 87 |\n| 乙 | 92 |\n| 丙 | 71 |"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
import:
|
||||
io: "std:io"
|
||||
format: "std:format"
|
||||
json: "std:data/json"
|
||||
text_lib: "std:text"
|
||||
utf8: "std:text/utf8"
|
||||
path: "std:path"
|
||||
datetime: "std:datetime"
|
||||
---
|
||||
|
||||
# @exec bundle
|
||||
|
||||
## main
|
||||
|
||||
**内存 = memory.new(1, 4)**
|
||||
|
||||
**长度 = text_lib.utf8编码("é", 内存, 0)**
|
||||
|
||||
**解码 = utf8.解码(内存, 0, 长度)**
|
||||
|
||||
**对象 = json.解析("[1, 2]")**
|
||||
|
||||
**时间 = datetime.格式化(1795248000123)**
|
||||
|
||||
> **io.写值("default-bundle")**
|
||||
|
||||
`return [长度, 内存[0], 内存[1], 解码.value, format.显示(["ok", 3]), json.格式化(对象.value), path.连接(["a", "b", "c"]), 时间, format.字节长度("é")]`
|
||||
@@ -1,42 +0,0 @@
|
||||
---
|
||||
import:
|
||||
io: "std:io"
|
||||
---
|
||||
|
||||
## @exec 演示函数
|
||||
|
||||
`return 1`
|
||||
|
||||
## @exec main
|
||||
|
||||
### @knowledge 公式
|
||||
|
||||
$$a = 1$$
|
||||
|
||||
### @knowledge 代码
|
||||
|
||||
```text
|
||||
print(1)
|
||||
```
|
||||
|
||||
### @exec 主流程
|
||||
|
||||
**列表 = ["文本", 2, 1.5, [3, true], {a: 1, b: "x"}, None]**
|
||||
|
||||
> **io.写值(列表)**
|
||||
|
||||
> **打印(列表)**
|
||||
|
||||
**表格 = 表(["名称", "分数"], [["甲", 87], ["乙", 92]])**
|
||||
|
||||
> **io.写值(表格)**
|
||||
|
||||
> **打印(表格)**
|
||||
|
||||
**特殊 = [ref("#公式"), ref("#代码"), ref("#演示函数")]**
|
||||
|
||||
> **io.写值(特殊)**
|
||||
|
||||
> **打印(特殊)**
|
||||
|
||||
`return None`
|
||||
@@ -1,31 +0,0 @@
|
||||
---
|
||||
import:
|
||||
table_lib: "std:collections/table"
|
||||
gfm_lib: "std:data/table"
|
||||
---
|
||||
|
||||
# @exec table
|
||||
|
||||
## main
|
||||
|
||||
**数据 = 表(["名称", "分数"], [["甲", 87], ["乙", 92], ["丙", 71]])**
|
||||
|
||||
**选择 = table_lib.选择列(数据, 1)**
|
||||
|
||||
**过滤 = table_lib.过滤数值大于(数据, 1, 80)**
|
||||
|
||||
**排序 = table_lib.排序(数据, 1)**
|
||||
|
||||
**追加 = table_lib.追加行(数据, ["丁", 65])**
|
||||
|
||||
**设置 = table_lib.设置单元格(数据, 0, 1, 99)**
|
||||
|
||||
**左 = 表(["名称", "分数"], [["甲", 87], ["乙", 92]])**
|
||||
|
||||
**右 = 表(["名称", "等级"], [["乙", "A"], ["甲", "B"]])**
|
||||
|
||||
**连接 = table_lib.连接(左, 右, 0, 0)**
|
||||
|
||||
**分组 = table_lib.分组(表(["类别", "值"], [["a", 1], ["b", 2], ["a", 3]]), 0, 1)**
|
||||
|
||||
`return [选择, 过滤, 排序, 追加, 设置, 连接, 分组, 数据, gfm_lib.转GFM(数据)]`
|
||||
@@ -1,368 +0,0 @@
|
||||
"""Contract tests for the root-owned, unique stdlib Bundle producer.
|
||||
|
||||
These tests build real temporary Git repositories so the producer is exercised
|
||||
through its real identity path: root catalog + exact gitlinks + component module
|
||||
trees. They never call a network remote and never use the repository's own
|
||||
Bundles.
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "build-stdlib.py"
|
||||
SPEC = importlib.util.spec_from_file_location("build_stdlib", SCRIPT)
|
||||
producer = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(producer)
|
||||
|
||||
GIT_ENV = {
|
||||
"GIT_AUTHOR_NAME": "test",
|
||||
"GIT_AUTHOR_EMAIL": "test@example.invalid",
|
||||
"GIT_COMMITTER_NAME": "test",
|
||||
"GIT_COMMITTER_EMAIL": "test@example.invalid",
|
||||
}
|
||||
|
||||
|
||||
def git(cwd, *args, check=True):
|
||||
env = os.environ.copy()
|
||||
env.update(GIT_ENV)
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(cwd), *args], capture_output=True, env=env
|
||||
)
|
||||
if check and result.returncode != 0:
|
||||
raise AssertionError(
|
||||
f"git {' '.join(args)} failed: {result.stderr.decode(errors='replace')}"
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def init_repo(path: Path) -> Path:
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
git(path, "init", "-q")
|
||||
return path
|
||||
|
||||
|
||||
def commit_all(repo: Path, message: str = "fixture") -> str:
|
||||
git(repo, "add", "-A")
|
||||
git(repo, "commit", "-q", "-m", message)
|
||||
return git(repo, "rev-parse", "HEAD").stdout.decode().strip()
|
||||
|
||||
|
||||
def write(path: Path, data) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(data if isinstance(data, bytes) else data.encode())
|
||||
|
||||
|
||||
def component(repo: Path, files: dict) -> str:
|
||||
init_repo(repo)
|
||||
for relative, data in files.items():
|
||||
write(repo / relative, data)
|
||||
return commit_all(repo)
|
||||
|
||||
|
||||
def catalog(*components: dict) -> str:
|
||||
blocks = []
|
||||
for component_spec in components:
|
||||
lines = ["[[component]]"]
|
||||
for key, value in component_spec.items():
|
||||
if isinstance(value, list):
|
||||
rendered = "[" + ", ".join(json.dumps(item) for item in value) + "]"
|
||||
else:
|
||||
rendered = json.dumps(value)
|
||||
lines.append(f"{key} = {rendered}")
|
||||
blocks.append("\n".join(lines))
|
||||
return "\n\n".join(blocks) + "\n"
|
||||
|
||||
|
||||
def root_repo(path: Path, catalog_text: str, links: dict, config: dict) -> str:
|
||||
init_repo(path)
|
||||
write(path / "components.toml", catalog_text)
|
||||
write(path / "scripts/stdlib-bundle.json", json.dumps(config, indent=2))
|
||||
for relative, sha in links.items():
|
||||
git(path, "update-index", "--add", "--cacheinfo", f"160000,{sha},{relative}")
|
||||
git(path, "add", "components.toml", "scripts/stdlib-bundle.json")
|
||||
git(path, "commit", "-q", "-m", "root fixture")
|
||||
return git(path, "rev-parse", "HEAD").stdout.decode().strip()
|
||||
|
||||
|
||||
def base_config(version="0.1.0", aliases=None) -> dict:
|
||||
return {
|
||||
"name": "marqdo-stdlib",
|
||||
"version": version,
|
||||
"public_aliases": aliases or [],
|
||||
}
|
||||
|
||||
|
||||
def std_component(component_id: str, path: str, state="active") -> dict:
|
||||
return {
|
||||
"id": component_id,
|
||||
"path": path,
|
||||
"kind": "stdlib",
|
||||
"state": state,
|
||||
"owner": "test",
|
||||
"scope": "fixture",
|
||||
"requires": ["cli"],
|
||||
"checks_with": [],
|
||||
"release": "base",
|
||||
} | ({"entry": "scripts/test.sh"} if state == "active" else {})
|
||||
|
||||
|
||||
class ProducerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self.tmp.name) / "root"
|
||||
self.root.mkdir()
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def build(self, *extra):
|
||||
import contextlib
|
||||
import io
|
||||
|
||||
out = Path(self.tmp.name) / (
|
||||
"out-" + str(len(list(Path(self.tmp.name).glob("out-*"))))
|
||||
)
|
||||
buffer = io.StringIO()
|
||||
with contextlib.redirect_stdout(buffer):
|
||||
status = producer.main(
|
||||
["--out", str(out), "--root", str(self.root), *extra]
|
||||
)
|
||||
self.assertEqual(status, 0)
|
||||
return buffer.getvalue(), out
|
||||
|
||||
def make_two_components(self):
|
||||
text = component(
|
||||
self.root / "stdlib/text",
|
||||
{
|
||||
"modules/text.mq.md": "# @exec text\n",
|
||||
"modules/text/utf8.mq.md": "# @exec utf8\n",
|
||||
"modules/README.md": "not published\n",
|
||||
},
|
||||
)
|
||||
io = component(
|
||||
self.root / "stdlib/io",
|
||||
{
|
||||
"modules/io.mq.md": "# @exec io\n",
|
||||
"modules/io/console.mq.md": "# @exec console\n",
|
||||
},
|
||||
)
|
||||
return text, io
|
||||
|
||||
def two_component_root(self, text_sha, io_sha, version="0.1.0", aliases=None):
|
||||
cat = catalog(
|
||||
std_component("std-text", "stdlib/text"),
|
||||
std_component("std-io", "stdlib/io"),
|
||||
)
|
||||
return root_repo(
|
||||
self.root,
|
||||
cat,
|
||||
{"stdlib/text": text_sha, "stdlib/io": io_sha},
|
||||
base_config(version, aliases),
|
||||
)
|
||||
|
||||
def test_builds_deterministic_bundle_and_excludes_non_modules(self):
|
||||
text_sha, io_sha = self.make_two_components()
|
||||
self.two_component_root(text_sha, io_sha)
|
||||
summary_one, out_one = self.build()
|
||||
payload = json.loads(summary_one)
|
||||
self.assertEqual(payload["files"], [
|
||||
"io.mq.md",
|
||||
"io/console.mq.md",
|
||||
"text.mq.md",
|
||||
"text/utf8.mq.md",
|
||||
])
|
||||
self.assertNotIn("README.md", payload["files"])
|
||||
manifest = json.loads((out_one / "stdlib.json").read_text())
|
||||
self.assertEqual(manifest["name"], "marqdo-stdlib")
|
||||
self.assertEqual(manifest["version"], "0.1.0")
|
||||
self.assertEqual(manifest["digest"], payload["tree_digest"])
|
||||
self.assertEqual(
|
||||
manifest["aliases_digest"], producer.aliases_digest([])
|
||||
)
|
||||
summary_two, out_two = self.build()
|
||||
self.assertEqual(
|
||||
json.loads(summary_two)["tree_digest"], payload["tree_digest"]
|
||||
)
|
||||
for relative in payload["files"]:
|
||||
self.assertEqual(
|
||||
(out_one / relative).read_bytes(), (out_two / relative).read_bytes()
|
||||
)
|
||||
self.assertEqual(
|
||||
(out_one / "stdlib.json").read_bytes(),
|
||||
(out_two / "stdlib.json").read_bytes(),
|
||||
)
|
||||
|
||||
def test_worktree_mode_requires_clean_components(self):
|
||||
self.make_two_components()
|
||||
write(
|
||||
self.root / "components.toml",
|
||||
catalog(
|
||||
std_component("std-text", "stdlib/text"),
|
||||
std_component("std-io", "stdlib/io"),
|
||||
),
|
||||
)
|
||||
write(
|
||||
self.root / "scripts/stdlib-bundle.json",
|
||||
json.dumps(base_config(), indent=2),
|
||||
)
|
||||
out = Path(self.tmp.name) / "w"
|
||||
producer.main(["--out", str(out), "--root", str(self.root), "--worktree"])
|
||||
self.assertTrue((out / "text.mq.md").is_file())
|
||||
write(self.root / "stdlib/text/modules/dirty.mq.md", "# @exec dirty\n")
|
||||
with self.assertRaises(SystemExit):
|
||||
producer.main([
|
||||
"--out", str(Path(self.tmp.name) / "w2"),
|
||||
"--root", str(self.root),
|
||||
"--worktree",
|
||||
])
|
||||
|
||||
def test_planned_component_is_not_published(self):
|
||||
text_sha, _ = self.make_two_components()
|
||||
planned_sha = component(
|
||||
self.root / "stdlib/net", {"modules/net/tcp.mq.md": "# @exec tcp\n"}
|
||||
)
|
||||
cat = catalog(
|
||||
std_component("std-text", "stdlib/text"),
|
||||
std_component("std-net", "stdlib/net", state="planned"),
|
||||
)
|
||||
root_repo(
|
||||
self.root,
|
||||
cat,
|
||||
{"stdlib/text": text_sha, "stdlib/net": planned_sha},
|
||||
base_config(),
|
||||
)
|
||||
summary, out = self.build()
|
||||
self.assertEqual(json.loads(summary)["files"], ["text.mq.md", "text/utf8.mq.md"])
|
||||
self.assertFalse((out / "net/tcp.mq.md").exists())
|
||||
|
||||
def test_duplicate_and_case_colliding_paths_are_rejected(self):
|
||||
text_sha, _ = self.make_two_components()
|
||||
clash_sha = component(
|
||||
self.root / "stdlib/other", {"modules/Text.mq.md": "# @exec clash\n"}
|
||||
)
|
||||
cat = catalog(
|
||||
std_component("std-text", "stdlib/text"),
|
||||
std_component("std-other", "stdlib/other"),
|
||||
)
|
||||
root_repo(
|
||||
self.root,
|
||||
cat,
|
||||
{"stdlib/text": text_sha, "stdlib/other": clash_sha},
|
||||
base_config(),
|
||||
)
|
||||
with self.assertRaises(SystemExit):
|
||||
self.build()
|
||||
|
||||
def test_non_nfc_and_symlink_entries_are_rejected(self):
|
||||
import unicodedata
|
||||
|
||||
decomposed = unicodedata.normalize("NFD", "text/café.mq.md")
|
||||
text_sha = component(
|
||||
self.root / "stdlib/text",
|
||||
{"modules/text.mq.md": "# @exec text\n", f"modules/{decomposed}": "# x\n"},
|
||||
)
|
||||
io_sha = component(
|
||||
self.root / "stdlib/io", {"modules/io.mq.md": "# @exec io\n"}
|
||||
)
|
||||
self.two_component_root(text_sha, io_sha)
|
||||
with self.assertRaises(SystemExit):
|
||||
self.build()
|
||||
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
try:
|
||||
root = Path(tmp.name) / "sr"
|
||||
root.mkdir()
|
||||
text = root / "stdlib/text"
|
||||
init_repo(text)
|
||||
write(text / "modules/text.mq.md", "# @exec text\n")
|
||||
(text / "modules/link.mq.md").symlink_to("text.mq.md")
|
||||
sha = commit_all(text)
|
||||
io = component(root / "stdlib/io", {"modules/io.mq.md": "# @exec io\n"})
|
||||
cat = catalog(
|
||||
std_component("std-text", "stdlib/text"),
|
||||
std_component("std-io", "stdlib/io"),
|
||||
)
|
||||
root_repo(root, cat, {"stdlib/text": sha, "stdlib/io": io}, base_config())
|
||||
with self.assertRaises(SystemExit):
|
||||
producer.main(["--out", str(root / "bundle"), "--root", str(root)])
|
||||
finally:
|
||||
tmp.cleanup()
|
||||
|
||||
def test_active_component_without_modules_is_rejected(self):
|
||||
text_sha, io_sha = self.make_two_components()
|
||||
empty_sha = component(self.root / "stdlib/empty", {"README.md": "x\n"})
|
||||
cat = catalog(
|
||||
std_component("std-text", "stdlib/text"),
|
||||
std_component("std-io", "stdlib/io"),
|
||||
std_component("std-empty", "stdlib/empty"),
|
||||
)
|
||||
root_repo(
|
||||
self.root,
|
||||
cat,
|
||||
{
|
||||
"stdlib/text": text_sha,
|
||||
"stdlib/io": io_sha,
|
||||
"stdlib/empty": empty_sha,
|
||||
},
|
||||
base_config(),
|
||||
)
|
||||
with self.assertRaises(SystemExit):
|
||||
self.build()
|
||||
|
||||
def test_content_change_requires_explicit_version_bump(self):
|
||||
text_sha, io_sha = self.make_two_components()
|
||||
self.two_component_root(text_sha, io_sha)
|
||||
_, out = self.build()
|
||||
baseline = out / "stdlib.json"
|
||||
changed = component(
|
||||
self.root / "stdlib/io",
|
||||
{
|
||||
"modules/io.mq.md": "# @exec io\n# changed\n",
|
||||
"modules/io/console.mq.md": "# @exec console\n",
|
||||
},
|
||||
)
|
||||
git(self.root, "reset", "-q", "--hard", "HEAD")
|
||||
self.two_component_root(text_sha, changed)
|
||||
with self.assertRaises(SystemExit):
|
||||
self.build("--baseline-manifest", str(baseline))
|
||||
new_root = self.two_component_root(text_sha, changed, version="0.2.0")
|
||||
self.assertIsNotNone(new_root)
|
||||
summary, out_two = self.build("--baseline-manifest", str(baseline))
|
||||
self.assertEqual(json.loads(summary)["version"], "0.2.0")
|
||||
|
||||
def test_public_alias_must_target_a_published_module(self):
|
||||
text_sha, io_sha = self.make_two_components()
|
||||
alias = {
|
||||
"public_names": ["print", "打印"],
|
||||
"target_module": "io.mq.md",
|
||||
"target_function": "写值",
|
||||
"expected_signature": "params(值)",
|
||||
"effects": ["host"],
|
||||
}
|
||||
self.two_component_root(text_sha, io_sha, aliases=[alias])
|
||||
summary, out = self.build()
|
||||
manifest = json.loads((out / "stdlib.json").read_text())
|
||||
self.assertEqual(
|
||||
manifest["aliases_digest"], json.loads(summary)["aliases_digest"]
|
||||
)
|
||||
bad = dict(alias, target_module="missing.mq.md")
|
||||
git(self.root, "reset", "-q", "--hard", "HEAD")
|
||||
self.two_component_root(text_sha, io_sha, aliases=[bad])
|
||||
with self.assertRaises(SystemExit):
|
||||
self.build()
|
||||
|
||||
def test_digest_algorithm_vector(self):
|
||||
import hashlib
|
||||
|
||||
files = {"a.mq.md": b"content"}
|
||||
expected = "sha256:" + hashlib.sha256(b"a.mq.md\0content\0").hexdigest()
|
||||
self.assertEqual(producer.tree_digest(files), expected)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,259 +0,0 @@
|
||||
"""Candidate notification authorization contract tests (issue #3).
|
||||
|
||||
Fixtures are real temporary Git repositories: a root catalog with `.gitmodules`
|
||||
and gitlinks, a component repository with two commits, and normalized
|
||||
notifications. The verifier must refuse forged/replayed/stale/failed candidates
|
||||
and never claim an auto-promotion action.
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
IMPACT_SPEC = importlib.util.spec_from_file_location("impact", ROOT / "scripts/impact.py")
|
||||
impact = importlib.util.module_from_spec(IMPACT_SPEC)
|
||||
IMPACT_SPEC.loader.exec_module(impact)
|
||||
NOTIFY_SPEC = importlib.util.spec_from_file_location(
|
||||
"candidate_notify", ROOT / "scripts/candidate-notify.py"
|
||||
)
|
||||
notify = importlib.util.module_from_spec(NOTIFY_SPEC)
|
||||
NOTIFY_SPEC.loader.exec_module(notify)
|
||||
|
||||
GIT_ENV = {
|
||||
"GIT_AUTHOR_NAME": "test",
|
||||
"GIT_AUTHOR_EMAIL": "test@example.invalid",
|
||||
"GIT_COMMITTER_NAME": "test",
|
||||
"GIT_COMMITTER_EMAIL": "test@example.invalid",
|
||||
}
|
||||
CI = {"status": "success", "url": "https://ci.cflmy.cn/repos/6/pipeline/1/1"}
|
||||
|
||||
|
||||
def git(cwd, *args, check=True):
|
||||
env = os.environ.copy()
|
||||
env.update(GIT_ENV)
|
||||
result = subprocess.run(["git", "-C", str(cwd), *args], capture_output=True, env=env)
|
||||
if check and result.returncode != 0:
|
||||
raise AssertionError(
|
||||
f"git {' '.join(args)} failed: {result.stderr.decode(errors='replace')}"
|
||||
)
|
||||
return result.stdout.decode()
|
||||
|
||||
|
||||
def init(path: Path) -> Path:
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
git(path, "init", "-q")
|
||||
return path
|
||||
|
||||
|
||||
def write(path: Path, data: str) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(data)
|
||||
|
||||
|
||||
def commit(repo: Path, message: str = "fixture") -> str:
|
||||
git(repo, "add", "-A")
|
||||
git(repo, "commit", "-q", "-m", message)
|
||||
return git(repo, "rev-parse", "HEAD").strip()
|
||||
|
||||
|
||||
def catalog(cli_sha_gitlink: bool = True) -> str:
|
||||
return """[[component]]
|
||||
id = "cli"
|
||||
path = "cli"
|
||||
kind = "core"
|
||||
state = "active"
|
||||
owner = "t"
|
||||
scope = "s"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-text"
|
||||
path = "stdlib/text"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "t"
|
||||
scope = "s"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
"""
|
||||
|
||||
|
||||
GITMODULES = """[submodule "cli"]
|
||||
\tpath = cli
|
||||
\turl = https://git.cflmy.cn/cflmy/marqdo-cli.git
|
||||
[submodule "stdlib/text"]
|
||||
\tpath = stdlib/text
|
||||
\turl = https://git.cflmy.cn/cflmy/marqdo-std-text.git
|
||||
"""
|
||||
|
||||
|
||||
class NotifyTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.base = Path(self.tmp.name)
|
||||
self.root = self.base / "root"
|
||||
init(self.root)
|
||||
write(self.root / "components.toml", catalog())
|
||||
write(self.root / ".gitmodules", GITMODULES)
|
||||
self.cli = init(self.root / "cli")
|
||||
write(self.cli / "README.md", "cli")
|
||||
self.cli_sha1 = commit(self.cli)
|
||||
self.text = init(self.root / "stdlib/text")
|
||||
write(self.text / "README.md", "text")
|
||||
self.text_sha1 = commit(self.text)
|
||||
git(self.root, "add", "components.toml", ".gitmodules")
|
||||
git(self.root, "update-index", "--add", "--cacheinfo", f"160000,{self.cli_sha1},cli")
|
||||
git(
|
||||
self.root, "update-index", "--add", "--cacheinfo",
|
||||
f"160000,{self.text_sha1},stdlib/text",
|
||||
)
|
||||
git(self.root, "commit", "-q", "-m", "accepted root")
|
||||
self.accepted = git(self.root, "rev-parse", "HEAD").strip()
|
||||
# Candidate component commit after the accepted root was frozen.
|
||||
write(self.cli / "README.md", "cli v2")
|
||||
self.cli_sha2 = commit(self.cli, "candidate")
|
||||
# Candidate root commit moving the cli gitlink.
|
||||
git(self.root, "update-index", "--cacheinfo", f"160000,{self.cli_sha2},cli")
|
||||
git(self.root, "commit", "-q", "-m", "candidate root")
|
||||
self.candidate_root = git(self.root, "rev-parse", "HEAD").strip()
|
||||
self.notify_original_root = notify.ROOT
|
||||
self.impact_original_root = impact.ROOT
|
||||
notify.ROOT = self.root
|
||||
impact.ROOT = self.root
|
||||
self.state = self.base / "state.json"
|
||||
|
||||
def tearDown(self):
|
||||
notify.ROOT = self.notify_original_root
|
||||
impact.ROOT = self.impact_original_root
|
||||
self.tmp.cleanup()
|
||||
|
||||
def notification(self, **overrides) -> Path:
|
||||
data = {
|
||||
"schema": "marqdo.candidate-notification",
|
||||
"schema_version": 1,
|
||||
"repository": "cflmy/marqdo-cli",
|
||||
"kind": "component",
|
||||
"component": "cli",
|
||||
"head_sha": self.cli_sha2,
|
||||
"base_sha": self.cli_sha1,
|
||||
"ci": dict(CI),
|
||||
"pull_request": 17,
|
||||
}
|
||||
data.update(overrides)
|
||||
path = self.base / "notification.json"
|
||||
path.write_text(json.dumps(data))
|
||||
return path
|
||||
|
||||
def run_verify(self, path: Path, accepted: str | None = None, write_state: bool = True):
|
||||
try:
|
||||
return notify.verify(
|
||||
json.loads(path.read_text()),
|
||||
accepted or self.accepted,
|
||||
self.state,
|
||||
["ci.cflmy.cn"],
|
||||
"cflmy/marqdo",
|
||||
write_state=write_state,
|
||||
)
|
||||
except notify.NotificationError as error:
|
||||
return {"verified": False, "reason": str(error)}
|
||||
|
||||
def test_component_candidate_verified_with_consumers_and_no_auto_promotion(self):
|
||||
plan = self.run_verify(self.notification())
|
||||
self.assertTrue(plan["verified"])
|
||||
self.assertIn("std-text", plan["impact"]["affected"])
|
||||
self.assertFalse(plan["actions"]["auto_promote"])
|
||||
self.assertFalse(plan["actions"]["auto_merge"])
|
||||
self.assertTrue(plan["actions"]["requires_human_review"])
|
||||
self.assertTrue(self.state.is_file())
|
||||
|
||||
def test_unknown_repository_is_rejected(self):
|
||||
plan = self.run_verify(self.notification(repository="cflmy/unknown"))
|
||||
self.assertFalse(plan["verified"])
|
||||
self.assertIn("unknown repository", plan["reason"])
|
||||
|
||||
def test_failed_ci_is_rejected(self):
|
||||
plan = self.run_verify(self.notification(ci={"status": "failure", "url": CI["url"]}))
|
||||
self.assertFalse(plan["verified"])
|
||||
self.assertIn("CI status", plan["reason"])
|
||||
|
||||
def test_non_allowlisted_ci_host_is_rejected(self):
|
||||
plan = self.run_verify(
|
||||
self.notification(ci={"status": "success", "url": "https://evil.example/p/1"})
|
||||
)
|
||||
self.assertFalse(plan["verified"])
|
||||
self.assertIn("CI URL", plan["reason"])
|
||||
|
||||
def test_unreachable_commit_is_rejected(self):
|
||||
plan = self.run_verify(self.notification(head_sha="0" * 40))
|
||||
self.assertFalse(plan["verified"])
|
||||
self.assertIn("not reachable", plan["reason"])
|
||||
|
||||
def test_stale_base_sha_is_rejected(self):
|
||||
plan = self.run_verify(
|
||||
self.notification(base_sha=self.text_sha1)
|
||||
)
|
||||
self.assertFalse(plan["verified"])
|
||||
self.assertIn("base_sha is stale", plan["reason"])
|
||||
|
||||
def test_replay_is_rejected_and_new_baseline_requires_revalidation(self):
|
||||
first = self.run_verify(self.notification())
|
||||
self.assertTrue(first["verified"])
|
||||
replay = self.run_verify(self.notification())
|
||||
self.assertFalse(replay["verified"])
|
||||
self.assertIn("duplicate/replay", replay["reason"])
|
||||
# A new accepted baseline that still pins the same component SHA (here
|
||||
# another component moved) must re-validate the same candidate.
|
||||
write(self.text / "README.md", "text v2")
|
||||
text_sha2 = commit(self.text, "text candidate")
|
||||
git(self.root, "update-index", "--cacheinfo", f"160000,{self.cli_sha1},cli")
|
||||
git(self.root, "update-index", "--cacheinfo", f"160000,{text_sha2},stdlib/text")
|
||||
git(self.root, "commit", "-q", "-m", "baseline 2")
|
||||
baseline2 = git(self.root, "rev-parse", "HEAD").strip()
|
||||
revalidated = self.run_verify(self.notification(), accepted=baseline2)
|
||||
self.assertTrue(revalidated["verified"], revalidated.get("reason"))
|
||||
self.assertTrue(revalidated["revalidate"])
|
||||
|
||||
def test_root_candidate_uses_union_graph_diff(self):
|
||||
plan = self.run_verify(
|
||||
self.notification(
|
||||
repository="cflmy/marqdo",
|
||||
kind="root",
|
||||
component=None,
|
||||
head_sha=self.candidate_root,
|
||||
base_sha=self.accepted,
|
||||
)
|
||||
)
|
||||
self.assertTrue(plan["verified"])
|
||||
self.assertEqual([c["id"] for c in plan["impact"]["changed"]], ["cli"])
|
||||
self.assertIn("std-text", plan["impact"]["affected"])
|
||||
|
||||
def test_root_repository_must_be_named_explicitly(self):
|
||||
plan = self.run_verify(
|
||||
self.notification(
|
||||
repository="cflmy/marqdo-cli",
|
||||
kind="root",
|
||||
head_sha=self.candidate_root,
|
||||
base_sha=self.accepted,
|
||||
)
|
||||
)
|
||||
self.assertFalse(plan["verified"])
|
||||
self.assertIn("unknown root repository", plan["reason"])
|
||||
|
||||
def test_state_is_not_written_in_dry_run(self):
|
||||
plan = self.run_verify(self.notification(), write_state=False)
|
||||
self.assertTrue(plan["verified"])
|
||||
self.assertFalse(self.state.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,274 +0,0 @@
|
||||
"""Recursive impact analysis contract tests (ECO-02 / issue #7).
|
||||
|
||||
Builds real temporary Git repositories for two root candidates and asserts the
|
||||
ordering required by the development contract: changed leaves, reverse
|
||||
`requires` closure over the union graph, parent domains, then `checks_with`
|
||||
fixed point; undetermined scope widens to the full candidate instead of being
|
||||
skipped.
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "impact.py"
|
||||
SPEC = importlib.util.spec_from_file_location("impact", SCRIPT)
|
||||
impact = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(impact)
|
||||
|
||||
GIT_ENV = {
|
||||
"GIT_AUTHOR_NAME": "test",
|
||||
"GIT_AUTHOR_EMAIL": "test@example.invalid",
|
||||
"GIT_COMMITTER_NAME": "test",
|
||||
"GIT_COMMITTER_EMAIL": "test@example.invalid",
|
||||
}
|
||||
|
||||
|
||||
def git(cwd, *args, check=True):
|
||||
env = os.environ.copy()
|
||||
env.update(GIT_ENV)
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(cwd), *args], capture_output=True, env=env
|
||||
)
|
||||
if check and result.returncode != 0:
|
||||
raise AssertionError(
|
||||
f"git {' '.join(args)} failed: {result.stderr.decode(errors='replace')}"
|
||||
)
|
||||
return result.stdout.decode()
|
||||
|
||||
|
||||
def init(path: Path) -> Path:
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
git(path, "init", "-q")
|
||||
return path
|
||||
|
||||
|
||||
def write(path: Path, data) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(data if isinstance(data, bytes) else data.encode())
|
||||
|
||||
|
||||
def commit(repo: Path, message: str = "fixture") -> str:
|
||||
git(repo, "add", "-A")
|
||||
git(repo, "commit", "-q", "-m", message)
|
||||
return git(repo, "rev-parse", "HEAD").strip()
|
||||
|
||||
|
||||
def component(**fields) -> str:
|
||||
lines = ["[[component]]"]
|
||||
for key, value in fields.items():
|
||||
if isinstance(value, list):
|
||||
rendered = "[" + ", ".join(f'"{item}"' for item in value) + "]"
|
||||
else:
|
||||
rendered = f'"{value}"'
|
||||
lines.append(f"{key} = {rendered}")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def catalog(*components: str) -> str:
|
||||
return "\n\n".join(components) + "\n"
|
||||
|
||||
|
||||
def leaf(base: Path, name: str, files: dict[str, str]) -> str:
|
||||
repo = init(base / name)
|
||||
for relative, data in files.items():
|
||||
write(repo / relative, data)
|
||||
return commit(repo)
|
||||
|
||||
|
||||
def root_repo(
|
||||
path: Path, catalog_text: str, links: dict[str, str], urls: dict[str, str] | None = None
|
||||
) -> str:
|
||||
init(path)
|
||||
write(path / "components.toml", catalog_text)
|
||||
if urls:
|
||||
modules = ["[submodule \"x\"]"]
|
||||
lines = []
|
||||
for link_path, url in urls.items():
|
||||
lines.extend([f"\tpath = {link_path}", f"\turl = {url}"])
|
||||
write(path / ".gitmodules", "\n".join(modules + lines) + "\n")
|
||||
git(path, "add", ".gitmodules")
|
||||
git(path, "add", "components.toml")
|
||||
for link_path, sha in links.items():
|
||||
git(path, "update-index", "--add", "--cacheinfo", f"160000,{sha},{link_path}")
|
||||
git(path, "commit", "-q", "-m", "root fixture")
|
||||
return git(path, "rev-parse", "HEAD").strip()
|
||||
|
||||
|
||||
COMPONENTS_V1 = catalog(
|
||||
component(id="cli", path="cli", kind="core", state="active", owner="t", scope="s",
|
||||
requires=[], checks_with=[], release="base"),
|
||||
component(id="std-core", path="stdlib/core", kind="stdlib", state="active", owner="t",
|
||||
scope="s", requires=["cli"], checks_with=[], release="base"),
|
||||
component(id="std-text", path="stdlib/text", kind="stdlib", state="active", owner="t",
|
||||
scope="s", requires=["cli", "std-core"], checks_with=["probe"], release="base"),
|
||||
component(id="probe", path="tools/probe", kind="tool", state="active", owner="t",
|
||||
scope="s", requires=["cli"], checks_with=["std-text"], release="optional"),
|
||||
component(id="tool", path="tools/tool", kind="tool", state="active", owner="t",
|
||||
scope="s", requires=["cli"], checks_with=[], release="optional"),
|
||||
)
|
||||
|
||||
|
||||
class ImpactTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.base = Path(self.tmp.name)
|
||||
self.root = self.base / "root"
|
||||
self.original_root = impact.ROOT
|
||||
|
||||
def tearDown(self):
|
||||
impact.ROOT = self.original_root
|
||||
self.tmp.cleanup()
|
||||
|
||||
def make_tree(self, catalog_text: str, leaves: dict[str, str]) -> str:
|
||||
return root_repo(self.root, catalog_text, {path: leaves[name] for name, path in {
|
||||
"cli": "cli", "std-core": "stdlib/core", "std-text": "stdlib/text",
|
||||
"probe": "tools/probe", "tool": "tools/tool",
|
||||
}.items() if name in leaves})
|
||||
|
||||
def leaf_shas(self):
|
||||
return {
|
||||
"cli": leaf(self.base, "cli", {"README.md": "cli"}),
|
||||
"std-core": leaf(self.base, "core", {"modules/core.mq.md": "# core\n"}),
|
||||
"std-text": leaf(self.base, "text", {"modules/text.mq.md": "# text\n"}),
|
||||
"probe": leaf(self.base, "probe", {"README.md": "probe"}),
|
||||
"tool": leaf(self.base, "tool", {"README.md": "tool"}),
|
||||
}
|
||||
|
||||
def analyze(self, first: str, second: str):
|
||||
impact.ROOT = self.root
|
||||
return impact.analyze(first, second)
|
||||
|
||||
def test_changed_leaf_closes_over_requires_then_checks_with(self):
|
||||
leaves = self.leaf_shas()
|
||||
first = self.make_tree(COMPONENTS_V1, leaves)
|
||||
leaves["std-core"] = leaf(self.base, "core2", {"modules/core.mq.md": "# core v2\n"})
|
||||
second = root_repo(
|
||||
self.root,
|
||||
COMPONENTS_V1,
|
||||
{
|
||||
"cli": leaves["cli"],
|
||||
"stdlib/core": leaves["std-core"],
|
||||
"stdlib/text": leaves["std-text"],
|
||||
"tools/probe": leaves["probe"],
|
||||
"tools/tool": leaves["tool"],
|
||||
},
|
||||
)
|
||||
report = self.analyze(first, second)
|
||||
self.assertEqual(
|
||||
[(c["id"], c["reason"]) for c in report["changed"]],
|
||||
[("std-core", "sha")],
|
||||
)
|
||||
self.assertEqual(report["affected"], ["probe", "std-core", "std-text"])
|
||||
self.assertEqual(report["checks_with"], ["probe"])
|
||||
self.assertNotIn("tool", report["affected"])
|
||||
|
||||
def test_removed_component_and_its_checks_with_partner_are_affected(self):
|
||||
leaves = self.leaf_shas()
|
||||
first = self.make_tree(COMPONENTS_V1, leaves)
|
||||
without_text = catalog(
|
||||
component(id="cli", path="cli", kind="core", state="active", owner="t",
|
||||
scope="s", requires=[], checks_with=[], release="base"),
|
||||
component(id="std-core", path="stdlib/core", kind="stdlib", state="active",
|
||||
owner="t", scope="s", requires=["cli"], checks_with=[], release="base"),
|
||||
component(id="probe", path="tools/probe", kind="tool", state="active", owner="t",
|
||||
scope="s", requires=["cli"], checks_with=["std-text"], release="optional"),
|
||||
component(id="tool", path="tools/tool", kind="tool", state="active", owner="t",
|
||||
scope="s", requires=["cli"], checks_with=[], release="optional"),
|
||||
)
|
||||
second = root_repo(
|
||||
self.root,
|
||||
without_text,
|
||||
{
|
||||
"cli": leaves["cli"],
|
||||
"stdlib/core": leaves["std-core"],
|
||||
"tools/probe": leaves["probe"],
|
||||
"tools/tool": leaves["tool"],
|
||||
},
|
||||
)
|
||||
report = self.analyze(first, second)
|
||||
self.assertIn({"id": "std-text", "reason": "removed"}, report["changed"])
|
||||
self.assertIn("probe", report["affected"])
|
||||
|
||||
def test_dependency_change_is_reported_and_widens_scope(self):
|
||||
leaves = self.leaf_shas()
|
||||
first = self.make_tree(COMPONENTS_V1, leaves)
|
||||
changed_text = COMPONENTS_V1.replace(
|
||||
'requires = ["cli", "std-core"]', 'requires = ["cli", "std-core", "tool"]'
|
||||
)
|
||||
second = self.make_tree(changed_text, leaves)
|
||||
report = self.analyze(first, second)
|
||||
self.assertEqual(
|
||||
[(c["id"], c["reason"]) for c in report["changed"]],
|
||||
[("std-text", "dependencies")],
|
||||
)
|
||||
self.assertIn("std-text", report["affected"])
|
||||
|
||||
def test_domain_gitlink_change_expands_to_child_identity(self):
|
||||
child = init(self.root / "extensions/web")
|
||||
write(child / "components.toml", catalog(
|
||||
component(id="web-design", path="design", kind="stdlib", state="planned",
|
||||
owner="t", scope="s", requires=["cli"], checks_with=[], release="base"),
|
||||
))
|
||||
design = leaf(self.base, "design", {"index.mq.md": "# design v1\n"})
|
||||
git(child, "add", "components.toml")
|
||||
git(child, "update-index", "--add", "--cacheinfo", f"160000,{design},design")
|
||||
git(child, "commit", "-q", "-m", "domain v1")
|
||||
domain_v1 = git(child, "rev-parse", "HEAD").strip()
|
||||
root_catalog = catalog(
|
||||
component(id="cli", path="cli", kind="core", state="active", owner="t",
|
||||
scope="s", requires=[], checks_with=[], release="base"),
|
||||
component(id="web", path="extensions/web", kind="domain", state="planned",
|
||||
owner="t", scope="s", requires=[], checks_with=[], release="none"),
|
||||
)
|
||||
first = root_repo(
|
||||
self.root,
|
||||
root_catalog,
|
||||
{"cli": leaf(self.base, "cli2", {"README.md": "cli"}), "extensions/web": domain_v1},
|
||||
{"extensions/web": "https://git.example.invalid/web.git"},
|
||||
)
|
||||
design_v2 = leaf(self.base, "design2", {"index.mq.md": "# design v2\n"})
|
||||
git(child, "update-index", "--cacheinfo", f"160000,{design_v2},design")
|
||||
git(child, "commit", "-q", "-m", "domain v2")
|
||||
domain_v2 = git(child, "rev-parse", "HEAD").strip()
|
||||
second = root_repo(
|
||||
self.root,
|
||||
root_catalog,
|
||||
{"cli": leaf(self.base, "cli3", {"README.md": "cli"}), "extensions/web": domain_v2},
|
||||
{"extensions/web": "https://git.example.invalid/web.git"},
|
||||
)
|
||||
report = self.analyze(first, second)
|
||||
self.assertIn("web", [c["id"] for c in report["changed"]])
|
||||
self.assertIn("web-design", [c["id"] for c in report["changed"]])
|
||||
self.assertIn("web-design", report["affected"])
|
||||
|
||||
def test_unexpandable_domain_widens_to_full_scope(self):
|
||||
root_catalog = catalog(
|
||||
component(id="cli", path="cli", kind="core", state="active", owner="t",
|
||||
scope="s", requires=[], checks_with=[], release="base"),
|
||||
component(id="web", path="extensions/web", kind="domain", state="planned",
|
||||
owner="t", scope="s", requires=[], checks_with=[], release="none"),
|
||||
)
|
||||
cli = leaf(self.base, "cli4", {"README.md": "cli"})
|
||||
first = root_repo(
|
||||
self.root, root_catalog,
|
||||
{"cli": cli, "extensions/web": leaf(self.base, "web1", {"README.md": "web"})},
|
||||
{"extensions/web": "https://git.example.invalid/web.git"},
|
||||
)
|
||||
second = root_repo(
|
||||
self.root, root_catalog,
|
||||
{"cli": cli, "extensions/web": leaf(self.base, "web2", {"README.md": "web2"})},
|
||||
{"extensions/web": "https://git.example.invalid/web.git"},
|
||||
)
|
||||
# The root fixture points at a plain repository without a components.toml.
|
||||
report = self.analyze(first, second)
|
||||
self.assertTrue(report["unverified"])
|
||||
self.assertEqual(report["fallback"], "full")
|
||||
self.assertEqual(report["affected"], ["cli", "web"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,721 +0,0 @@
|
||||
import importlib.util
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[2] / "scripts/check-layout.py"
|
||||
SPEC = importlib.util.spec_from_file_location("check_layout", SCRIPT)
|
||||
layout = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(layout)
|
||||
|
||||
CLI = '''
|
||||
[[component]]
|
||||
id = "cli"
|
||||
path = "cli"
|
||||
kind = "core"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "core implementation"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
'''
|
||||
|
||||
PLANNED = '''
|
||||
[[component]]
|
||||
id = "std-core"
|
||||
path = "stdlib/core"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "primitive utilities"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
'''
|
||||
|
||||
CORE_URL = "https://git.cflmy.cn/cflmy/marqdo-cli.git"
|
||||
|
||||
WEB_DOMAIN = '''
|
||||
[[component]]
|
||||
id = "web"
|
||||
path = "extensions/web"
|
||||
kind = "domain"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "web prototype domain governance"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "none"
|
||||
entry = "scripts/integration.sh"
|
||||
'''
|
||||
|
||||
STDLIB_DOMAIN = '''
|
||||
[[component]]
|
||||
id = "stdlib"
|
||||
path = "stdlib"
|
||||
kind = "domain"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "standard library bundle assembly"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/integration.sh"
|
||||
'''
|
||||
|
||||
DOMAIN = '''
|
||||
[[component]]
|
||||
id = "web-design"
|
||||
path = "design"
|
||||
kind = "extension"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "design document interpretation"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/ci.sh"
|
||||
|
||||
[[component]]
|
||||
id = "web-preview"
|
||||
path = "preview"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "prototype rendering"
|
||||
requires = ["cli", "web-design"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/ci.sh"
|
||||
|
||||
[[component]]
|
||||
id = "web-components"
|
||||
path = "components"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "design templates"
|
||||
requires = ["web-design"]
|
||||
checks_with = ["web-preview"]
|
||||
release = "optional"
|
||||
'''
|
||||
|
||||
|
||||
def catalog(*blocks):
|
||||
return "".join(blocks)
|
||||
|
||||
|
||||
class LayoutTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.enterContext(patch.object(layout, "ROOT", self.root))
|
||||
self.enterContext(patch.object(layout, "git", side_effect=self.git))
|
||||
self.git("init", "-q")
|
||||
self.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "--allow-empty", "-qm", "fixture")
|
||||
self.sha = self.git("rev-parse", "HEAD").strip()
|
||||
|
||||
def git(self, *args, cwd=None):
|
||||
return subprocess.check_output(["git", "-C", cwd or self.root, *args]).decode()
|
||||
|
||||
def candidate(self, metadata=CLI, url=CORE_URL, extra=None, file=None, extra_url=None):
|
||||
(self.root / "components.toml").write_text(metadata)
|
||||
modules = f'[submodule "cli"]\npath = cli\nurl = {url}\n'
|
||||
if extra_url:
|
||||
modules += f'[submodule "{extra}"]\npath = {extra}\nurl = {extra_url}\n'
|
||||
(self.root / ".gitmodules").write_text(modules)
|
||||
self.git("add", ".gitmodules", "components.toml")
|
||||
self.git("update-index", "--add", "--cacheinfo", f"160000,{self.sha},cli")
|
||||
if extra:
|
||||
self.git("update-index", "--add", "--cacheinfo", f"160000,{self.sha},{extra}")
|
||||
if file:
|
||||
path = self.root / file
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text("Fixture")
|
||||
self.git("add", file)
|
||||
self.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "candidate")
|
||||
|
||||
def test_accepts_active_gitlink_and_planned_component(self):
|
||||
self.candidate(CLI + PLANNED)
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_accepts_a_planned_component_directory_readme(self):
|
||||
self.candidate(CLI + PLANNED, file="stdlib/core/README.md")
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_source_under_a_planned_component(self):
|
||||
self.candidate(CLI + PLANNED, file="stdlib/core/result.mq.md")
|
||||
with self.assertRaisesRegex(ValueError, "unexpected tracked path or mode"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_an_unregistered_component_directory(self):
|
||||
self.candidate(CLI + PLANNED, file="stdlib/missing/README.md")
|
||||
with self.assertRaisesRegex(ValueError, "unexpected tracked path or mode"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_a_planned_gitlink_without_a_registered_remote(self):
|
||||
self.candidate(CLI + PLANNED, extra="stdlib/core")
|
||||
with self.assertRaisesRegex(ValueError, "missing or invalid submodule path: stdlib/core"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_accepts_a_planned_gitlink_with_its_remote(self):
|
||||
self.candidate(CLI + PLANNED, extra="stdlib/core",
|
||||
extra_url="https://git.cflmy.cn/cflmy/marqdo-std-core.git")
|
||||
root = layout.validate("HEAD", False)[0]
|
||||
self.assertEqual(root.linked["stdlib/core"]["state"], "planned")
|
||||
|
||||
def test_rejects_active_dependency_on_planned(self):
|
||||
self.candidate(CLI.replace("requires = []", 'requires = ["std-core"]') + PLANNED)
|
||||
with self.assertRaisesRegex(ValueError, "active depends on planned"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_other_host(self):
|
||||
self.candidate(url="https://example.invalid/cflmy/marqdo-cli.git")
|
||||
with self.assertRaisesRegex(ValueError, "invalid submodule URL"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_wrong_repository_at_authority(self):
|
||||
self.candidate(url="https://git.cflmy.cn/cflmy/marqdo-view.git")
|
||||
with self.assertRaisesRegex(ValueError, "invalid submodule URL"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_unstaged_checkout(self):
|
||||
self.candidate()
|
||||
with self.assertRaisesRegex(ValueError, "missing submodule checkout"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
|
||||
class HierarchicalLayoutTests(unittest.TestCase):
|
||||
"""End-to-end fixtures with real local Git repositories.
|
||||
|
||||
The fixture builds root -> domain -> two leaves using only local clones:
|
||||
no network remote is contacted, no ``git submodule update`` is executed.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
sources = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(sources.cleanup)
|
||||
self.sources = Path(sources.name)
|
||||
self.enterContext(patch.object(layout, "ROOT", self.root))
|
||||
self.enterContext(patch.object(layout, "git", side_effect=self.git))
|
||||
self.git("init", "-q", "-b", "main")
|
||||
self.git("commit", "--allow-empty", "-qm", "fixture")
|
||||
|
||||
def git(self, *args, cwd=None):
|
||||
return subprocess.check_output([
|
||||
"git",
|
||||
"-c", "user.name=Test",
|
||||
"-c", "user.email=test@example.invalid",
|
||||
"-C", str(cwd or self.root),
|
||||
*args,
|
||||
], stderr=subprocess.DEVNULL).decode()
|
||||
|
||||
# -- fixture primitives -------------------------------------------------
|
||||
|
||||
def repo(self, name):
|
||||
path = self.sources / name
|
||||
path.mkdir(parents=True)
|
||||
self.git("init", "-q", "-b", "main", cwd=path)
|
||||
return path
|
||||
|
||||
def write(self, repo, relative, content):
|
||||
path = Path(repo) / relative
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(content)
|
||||
|
||||
def stage(self, repo):
|
||||
self.git("add", "-A", cwd=repo)
|
||||
|
||||
def commit(self, repo, message):
|
||||
self.git("commit", "-qm", message, cwd=repo)
|
||||
return self.git("rev-parse", "HEAD", cwd=repo).strip()
|
||||
|
||||
def gitlink(self, repo, path, sha):
|
||||
self.git("update-index", "--add", "--cacheinfo", f"160000,{sha},{path}", cwd=repo)
|
||||
|
||||
def modules(self, repo, entries):
|
||||
self.write(repo, ".gitmodules", "".join(
|
||||
f'[submodule "{path}"]\n\tpath = {path}\n\turl = {url}\n' for path, url in entries.items()))
|
||||
|
||||
def leaf(self, name, entry="scripts/ci.sh", symlink_entry=False):
|
||||
repo = self.repo(name)
|
||||
if symlink_entry:
|
||||
self.write(repo, "scripts/real.sh", "#!/bin/sh\nexit 0\n")
|
||||
link = repo / entry
|
||||
link.parent.mkdir(parents=True, exist_ok=True)
|
||||
link.symlink_to("real.sh")
|
||||
else:
|
||||
self.write(repo, entry, "#!/bin/sh\nexit 0\n")
|
||||
self.stage(repo)
|
||||
return repo, self.commit(repo, f"leaf {name}")
|
||||
|
||||
def leaf_with_gitlink(self, name):
|
||||
inner = self.repo(f"{name}-inner")
|
||||
self.write(inner, "scripts/ci.sh", "#!/bin/sh\nexit 0\n")
|
||||
self.stage(inner)
|
||||
inner_sha = self.commit(inner, "inner")
|
||||
repo = self.repo(name)
|
||||
self.write(repo, "scripts/ci.sh", "#!/bin/sh\nexit 0\n")
|
||||
self.stage(repo)
|
||||
self.gitlink(repo, "nested/inner", inner_sha)
|
||||
return repo, self.commit(repo, f"leaf {name}")
|
||||
|
||||
def domain(self, catalog_text, links, files=None, modules=None):
|
||||
repo = self.repo("domain-source")
|
||||
if catalog_text is not None:
|
||||
self.write(repo, "components.toml", catalog_text)
|
||||
self.write(repo, "scripts/integration.sh", "#!/bin/sh\nexit 0\n")
|
||||
for relative, content in (files or {}).items():
|
||||
self.write(repo, relative, content)
|
||||
entries = {
|
||||
"design": "https://git.cflmy.cn/cflmy/marqdo-web-design.git",
|
||||
"preview": "https://git.cflmy.cn/cflmy/marqdo-web-preview.git",
|
||||
}
|
||||
if modules is not None:
|
||||
entries = modules
|
||||
self.modules(repo, entries)
|
||||
self.stage(repo)
|
||||
for path, sha in links.items():
|
||||
self.gitlink(repo, path, sha)
|
||||
return repo, self.commit(repo, "domain")
|
||||
|
||||
def root_repo(self, catalog_text, links, modules):
|
||||
self.write(self.root, "components.toml", catalog_text)
|
||||
self.modules(self.root, modules)
|
||||
self.stage(self.root)
|
||||
for path, sha in links.items():
|
||||
self.gitlink(self.root, path, sha)
|
||||
return self.commit(self.root, "root")
|
||||
|
||||
def clone(self, source, target, sha):
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.git("clone", "-q", str(source), str(target), cwd=self.sources)
|
||||
self.git("checkout", "-q", sha, cwd=target)
|
||||
|
||||
def assemble(self, domain_catalog=DOMAIN, domain_files=None, domain_modules=None,
|
||||
omit_domain_link=None, extra_domain_link=None, root_catalog=None,
|
||||
root_modules=None, checkout=True, core=None, design=None, preview=None):
|
||||
core = core or self.leaf("core", entry="scripts/test.sh")
|
||||
design = design or self.leaf("design")
|
||||
preview = preview or self.leaf("preview")
|
||||
links = {"design": design[1], "preview": preview[1]}
|
||||
if omit_domain_link:
|
||||
links.pop(omit_domain_link)
|
||||
if extra_domain_link:
|
||||
links[extra_domain_link[0]] = extra_domain_link[1]
|
||||
domain_repo, domain_sha = self.domain(domain_catalog, links, domain_files, domain_modules)
|
||||
modules = root_modules if root_modules is not None else {
|
||||
"cli": CORE_URL,
|
||||
"extensions/web": "https://git.cflmy.cn/cflmy/marqdo-ext-web.git",
|
||||
}
|
||||
self.root_repo(root_catalog if root_catalog is not None else catalog(CLI, WEB_DOMAIN),
|
||||
{"cli": core[1], "extensions/web": domain_sha}, modules)
|
||||
if checkout:
|
||||
self.clone(core[0], self.root / "cli", core[1])
|
||||
self.clone(domain_repo, self.root / "extensions/web", domain_sha)
|
||||
sources = {"design": design, "preview": preview}
|
||||
for path, sha in links.items():
|
||||
self.clone(sources.get(path, design)[0], self.root / "extensions/web" / path, sha)
|
||||
return {"core": core, "design": design, "preview": preview, "domain": (domain_repo, domain_sha)}
|
||||
|
||||
# -- positive cases -----------------------------------------------------
|
||||
|
||||
def test_accepts_a_two_level_domain_tree_with_checkouts(self):
|
||||
self.assemble(domain_files={"docs/WEB-DESIGN.md": "# contract\n", "examples/research/README.md": "example\n"})
|
||||
layout.validate("HEAD", True)
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_accepts_a_planned_domain_and_planned_child_gitlinks(self):
|
||||
web = WEB_DOMAIN.replace('state = "active"', 'state = "planned"').replace(
|
||||
'entry = "scripts/integration.sh"\n', '')
|
||||
children = DOMAIN.replace('state = "active"', 'state = "planned"').replace(
|
||||
'entry = "scripts/ci.sh"\n', '')
|
||||
self.assemble(root_catalog=CLI + web, domain_catalog=children)
|
||||
root, domain = layout.validate("HEAD", True)
|
||||
self.assertEqual(root.linked["extensions/web"]["state"], "planned")
|
||||
self.assertEqual(set(domain.linked), {"design", "preview"})
|
||||
self.assertTrue(all(child["state"] == "planned" for child in domain.linked.values()))
|
||||
|
||||
def test_non_checkout_mode_only_validates_the_root_layer(self):
|
||||
self.assemble()
|
||||
shutil.rmtree(self.root / "extensions" / "web")
|
||||
layout.validate("HEAD", False)
|
||||
with self.assertRaisesRegex(ValueError, "missing submodule checkout: extensions/web"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_accepts_a_stdlib_domain_with_base_release(self):
|
||||
self.root_repo(catalog(CLI, STDLIB_DOMAIN),
|
||||
{"cli": self.leaf("core", entry="scripts/test.sh")[1], "stdlib": "a" * 40},
|
||||
{"cli": CORE_URL, "stdlib": "https://git.cflmy.cn/cflmy/marqdo-stdlib.git"})
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_allows_checks_with_cycles(self):
|
||||
cycle = CLI.replace('checks_with = []', 'checks_with = ["view"]') + '''
|
||||
[[component]]
|
||||
id = "view"
|
||||
path = "tools/view"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "read and observe"
|
||||
requires = ["cli"]
|
||||
checks_with = ["cli"]
|
||||
release = "optional"
|
||||
entry = "scripts/acceptance.sh"
|
||||
'''
|
||||
sha = self.leaf("core", entry="scripts/test.sh")[1]
|
||||
self.root_repo(cycle, {"cli": sha, "tools/view": sha},
|
||||
{"cli": CORE_URL, "tools/view": "https://git.cflmy.cn/cflmy/marqdo-view.git"})
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
# -- checkout failures --------------------------------------------------
|
||||
|
||||
def test_rejects_a_dirty_domain_child(self):
|
||||
self.assemble()
|
||||
(self.root / "extensions/web/design/scratch.txt").write_text("dirty")
|
||||
with self.assertRaisesRegex(ValueError, r"domain web \(extensions/web\): dirty submodule: design"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_wrong_checked_out_commit(self):
|
||||
self.assemble()
|
||||
self.git("commit", "--allow-empty", "-qm", "drift", cwd=self.root / "extensions/web/design")
|
||||
with self.assertRaisesRegex(ValueError, r"domain web \(extensions/web\): wrong checked-out commit: design"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_missing_domain_child_checkout(self):
|
||||
self.assemble()
|
||||
shutil.rmtree(self.root / "extensions/web/preview")
|
||||
with self.assertRaisesRegex(ValueError, r"domain web \(extensions/web\): missing submodule checkout: preview"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_missing_committed_object(self):
|
||||
self.assemble()
|
||||
self.git("update-index", "--add", "--cacheinfo", f"160000,{'f' * 40},extensions/web", cwd=self.root)
|
||||
self.git("commit", "-qm", "bad gitlink")
|
||||
with self.assertRaisesRegex(ValueError, "missing committed object: extensions/web"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_symbolic_entry(self):
|
||||
design = self.leaf("design", symlink_entry=True)
|
||||
self.assemble(design=design)
|
||||
with self.assertRaisesRegex(ValueError, "missing or symbolic entry: design/scripts/ci.sh"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_third_level_gitlink(self):
|
||||
design = self.leaf_with_gitlink("design")
|
||||
self.assemble(design=design)
|
||||
with self.assertRaisesRegex(ValueError, r"domain web \(extensions/web\) leaf web-design \(design\): leaf must not register gitlinks"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
# -- catalog and layer failures ----------------------------------------
|
||||
|
||||
def test_rejects_a_missing_domain_catalog(self):
|
||||
self.assemble(domain_catalog=None)
|
||||
layout.validate("HEAD", False)
|
||||
with self.assertRaisesRegex(ValueError, "missing components.toml at"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_domain_catalog_missing_a_gitlink(self):
|
||||
extra = DOMAIN + '''
|
||||
[[component]]
|
||||
id = "web-extra"
|
||||
path = "extra"
|
||||
kind = "extension"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "extra component"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/ci.sh"
|
||||
'''
|
||||
self.assemble(domain_catalog=extra)
|
||||
with self.assertRaisesRegex(ValueError, r"domain web \(extensions/web\): gitlink/catalog mismatch"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_an_unregistered_domain_gitlink(self):
|
||||
info = self.assemble()
|
||||
extra = self.leaf("extra")
|
||||
domain_repo = self.sources / "domain-source"
|
||||
self.git("update-index", "--add", "--cacheinfo", f"160000,{extra[1]},extra", cwd=domain_repo)
|
||||
new_domain_sha = self.commit(domain_repo, "extra gitlink")
|
||||
self.git("update-index", "--add", "--cacheinfo", f"160000,{new_domain_sha},extensions/web", cwd=self.root)
|
||||
self.git("commit", "-qm", "advance domain")
|
||||
shutil.rmtree(self.root / "extensions/web")
|
||||
self.clone(domain_repo, self.root / "extensions/web", new_domain_sha)
|
||||
for name in ("design", "preview"):
|
||||
self.clone(info[name][0], self.root / "extensions/web" / name, info[name][1])
|
||||
self.clone(extra[0], self.root / "extensions/web" / "extra", extra[1])
|
||||
with self.assertRaisesRegex(ValueError, r"domain web \(extensions/web\): gitlink/catalog mismatch"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_nested_domain(self):
|
||||
nested = '''
|
||||
[[component]]
|
||||
id = "web-inner"
|
||||
path = "inner"
|
||||
kind = "domain"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "nested aggregate"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "none"
|
||||
'''
|
||||
self.assemble(domain_catalog=nested)
|
||||
with self.assertRaisesRegex(ValueError, "domain kind is only allowed at the root layer: web-inner"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_core_component_inside_a_domain(self):
|
||||
nested = '''
|
||||
[[component]]
|
||||
id = "web-core"
|
||||
path = "core"
|
||||
kind = "core"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "not allowed here"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "base"
|
||||
'''
|
||||
self.assemble(domain_catalog=nested)
|
||||
with self.assertRaisesRegex(ValueError, "component kind is not allowed inside a domain: web-core"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_production_file_in_the_domain_tree(self):
|
||||
self.assemble(domain_files={"Cargo.toml": '[package]\nname = "web-domain"\n'})
|
||||
with self.assertRaisesRegex(ValueError, "unexpected aggregate tracked path or mode: Cargo.toml"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_planned_child_implementation_file(self):
|
||||
self.assemble(domain_files={"components/renderer.py": "print('not allowed')\n"})
|
||||
with self.assertRaisesRegex(ValueError, "unexpected aggregate tracked path or mode: components/renderer.py"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_a_wrong_domain_child_url(self):
|
||||
self.assemble(domain_modules={
|
||||
"design": "https://git.cflmy.cn/cflmy/marqdo-ext-design.git",
|
||||
"preview": "https://git.cflmy.cn/cflmy/marqdo-web-preview.git",
|
||||
})
|
||||
shutil.rmtree(self.root / "extensions/web/design")
|
||||
with self.assertRaisesRegex(ValueError, "invalid submodule URL: design"):
|
||||
layout.validate("HEAD", False, expand_domains=True)
|
||||
|
||||
# -- global graph failures ---------------------------------------------
|
||||
|
||||
def test_rejects_a_duplicate_global_id(self):
|
||||
self.assemble(domain_catalog=DOMAIN.replace('id = "web-components"', 'id = "cli"'))
|
||||
with self.assertRaisesRegex(ValueError, "duplicate global id: cli"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_an_unknown_domain_dependency(self):
|
||||
self.assemble(domain_catalog=DOMAIN.replace('requires = ["cli"]', 'requires = ["cli", "missing"]', 1))
|
||||
with self.assertRaisesRegex(ValueError, "unknown dependency: web-design -> missing"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_an_active_domain_child_dependency_on_planned(self):
|
||||
self.assemble(domain_catalog=DOMAIN.replace(
|
||||
'requires = ["cli", "web-design"]', 'requires = ["cli", "web-design", "web-components"]', 1))
|
||||
with self.assertRaisesRegex(ValueError, "active depends on planned: web-preview -> web-components"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
# -- root catalog rules -------------------------------------------------
|
||||
|
||||
def test_rejects_domain_requires(self):
|
||||
self.root_repo(CLI + WEB_DOMAIN.replace("requires = []", 'requires = ["cli"]'),
|
||||
{"cli": "a" * 40, "extensions/web": "b" * 40},
|
||||
{"cli": CORE_URL, "extensions/web": "https://git.cflmy.cn/cflmy/marqdo-ext-web.git"})
|
||||
with self.assertRaisesRegex(ValueError, "domain requires must be empty: web"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_an_invalid_domain_release_role(self):
|
||||
self.root_repo(CLI + WEB_DOMAIN.replace('release = "none"', 'release = "optional"'),
|
||||
{"cli": "a" * 40, "extensions/web": "b" * 40},
|
||||
{"cli": CORE_URL, "extensions/web": "https://git.cflmy.cn/cflmy/marqdo-ext-web.git"})
|
||||
with self.assertRaisesRegex(ValueError, "invalid release role: web"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_an_invalid_domain_path(self):
|
||||
self.root_repo(CLI + WEB_DOMAIN.replace('path = "extensions/web"', 'path = "extensions/other"'),
|
||||
{"cli": "a" * 40, "extensions/other": "b" * 40},
|
||||
{"cli": CORE_URL, "extensions/other": "https://git.cflmy.cn/cflmy/marqdo-ext-web.git"})
|
||||
with self.assertRaisesRegex(ValueError, "invalid path: web: extensions/other"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_a_requires_edge_to_a_domain(self):
|
||||
view = '''
|
||||
[[component]]
|
||||
id = "view"
|
||||
path = "tools/view"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "read and observe"
|
||||
requires = ["web"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/acceptance.sh"
|
||||
'''
|
||||
self.root_repo(CLI + WEB_DOMAIN + view,
|
||||
{"cli": "a" * 40, "extensions/web": "b" * 40, "tools/view": "a" * 40},
|
||||
{"cli": CORE_URL,
|
||||
"extensions/web": "https://git.cflmy.cn/cflmy/marqdo-ext-web.git",
|
||||
"tools/view": "https://git.cflmy.cn/cflmy/marqdo-view.git"})
|
||||
with self.assertRaisesRegex(ValueError, "requires must not target a domain: view -> web"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_stdlib_dependency_on_extension(self):
|
||||
stdlib_extra = '''
|
||||
[[component]]
|
||||
id = "std-extra"
|
||||
path = "stdlib/extra"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "not allowed to depend on extensions"
|
||||
requires = ["math"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
'''
|
||||
math = '''
|
||||
[[component]]
|
||||
id = "math"
|
||||
path = "extensions/math"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "numeric algorithms"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
'''
|
||||
self.root_repo(CLI + stdlib_extra + math, {"cli": "a" * 40}, {"cli": CORE_URL})
|
||||
with self.assertRaisesRegex(ValueError, "stdlib dependency violation: std-extra -> math"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_core_build_dependency_on_other_component(self):
|
||||
conformance = '''
|
||||
[[component]]
|
||||
id = "conformance"
|
||||
path = "tests/conformance"
|
||||
kind = "test"
|
||||
state = "active"
|
||||
owner = "maintainer"
|
||||
scope = "independent protocol tests"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "none"
|
||||
entry = "scripts/build_all.sh"
|
||||
'''
|
||||
cli = CLI.replace("requires = []", 'requires = ["conformance"]')
|
||||
self.root_repo(cli + conformance,
|
||||
{"cli": "a" * 40, "tests/conformance": "a" * 40},
|
||||
{"cli": CORE_URL,
|
||||
"tests/conformance": "https://git.cflmy.cn/cflmy/marqdo-extension-conformance.git"})
|
||||
with self.assertRaisesRegex(ValueError, "dependency violation: cli must not require conformance"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_a_requires_cycle(self):
|
||||
math = '''
|
||||
[[component]]
|
||||
id = "math"
|
||||
path = "extensions/math"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "numeric algorithms"
|
||||
requires = ["linalg"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
'''
|
||||
linalg = '''
|
||||
[[component]]
|
||||
id = "linalg"
|
||||
path = "extensions/linalg"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "maintainer"
|
||||
scope = "linear algebra"
|
||||
requires = ["math"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
'''
|
||||
self.root_repo(CLI + math + linalg, {"cli": "a" * 40}, {"cli": CORE_URL})
|
||||
with self.assertRaisesRegex(ValueError, "requires DAG cycle"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_overlapping_component_paths(self):
|
||||
stdlib_domain = STDLIB_DOMAIN.replace("state = \"active\"", "state = \"planned\"").replace(
|
||||
'entry = "scripts/integration.sh"\n', "")
|
||||
planned = PLANNED
|
||||
self.root_repo(CLI + stdlib_domain + planned, {"cli": "a" * 40}, {"cli": CORE_URL})
|
||||
with self.assertRaisesRegex(ValueError, "overlapping component path: stdlib/core / stdlib"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_a_submodule_update_command(self):
|
||||
self.root_repo(CLI, {"cli": "a" * 40}, {"cli": CORE_URL})
|
||||
self.write(self.root, ".gitmodules",
|
||||
f'[submodule "cli"]\n\tpath = cli\n\turl = {CORE_URL}\n\tupdate = !false\n')
|
||||
self.stage(self.root)
|
||||
self.gitlink(self.root, "cli", "a" * 40)
|
||||
self.git("commit", "-qm", "update command")
|
||||
with self.assertRaisesRegex(ValueError, "unexpected submodule settings"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_forbidden_submodule_urls(self):
|
||||
for url in ("file:///tmp/marqdo-cli.git", "../marqdo-cli.git", "git@git.cflmy.cn:cflmy/marqdo-cli.git"):
|
||||
with self.subTest(url=url):
|
||||
self.root_repo(CLI, {"cli": "a" * 40}, {"cli": url})
|
||||
with self.assertRaisesRegex(ValueError, "invalid submodule URL: cli"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_accepts_a_submodule_section_name_that_differs_from_its_path(self):
|
||||
self.root_repo(CLI, {"cli": "a" * 40}, {"cli": CORE_URL})
|
||||
self.write(self.root, ".gitmodules",
|
||||
f'[submodule "core-runtime"]\n\tpath = cli\n\turl = {CORE_URL}\n')
|
||||
self.stage(self.root)
|
||||
self.gitlink(self.root, "cli", "a" * 40)
|
||||
self.git("commit", "-qm", "named section")
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_a_wrong_domain_root_url(self):
|
||||
self.root_repo(CLI + WEB_DOMAIN,
|
||||
{"cli": "a" * 40, "extensions/web": "b" * 40},
|
||||
{"cli": CORE_URL,
|
||||
"extensions/web": "https://git.cflmy.cn/cflmy/ext-web.git"})
|
||||
with self.assertRaisesRegex(ValueError, "invalid submodule URL: extensions/web"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_a_domain_without_submodule_gitmodules(self):
|
||||
self.assemble(domain_modules={})
|
||||
with self.assertRaisesRegex(ValueError, "missing or invalid submodule path: design"):
|
||||
layout.validate("HEAD", True)
|
||||
|
||||
def test_rejects_an_unknown_root_dependency(self):
|
||||
self.root_repo(CLI.replace('requires = []', 'requires = ["missing"]'), {"cli": "a" * 40}, {"cli": CORE_URL})
|
||||
with self.assertRaisesRegex(ValueError, "unknown dependency: cli -> missing"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
def test_rejects_an_absolute_or_parent_path(self):
|
||||
for path in ("/extensions/web", "extensions/../web", "extensions//web"):
|
||||
with self.subTest(path=path):
|
||||
self.root_repo(
|
||||
CLI + WEB_DOMAIN.replace('path = "extensions/web"', f'path = "{path}"'),
|
||||
{"cli": "a" * 40},
|
||||
{"cli": CORE_URL})
|
||||
with self.assertRaisesRegex(ValueError, "invalid path for web"):
|
||||
layout.validate("HEAD", False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Submodule tools/knowledge deleted from d8fa201b28.
-1
Submodule tools/lint deleted from 111e085f24.
-1
Submodule tools/prove deleted from d8c340b6e2.
-1
Submodule tools/view deleted from 04f3a0e9e5.
Reference in new issue
Block a user