Author SHA1 Message Date
cflmy a031fedb73 ci: package exact std-text source candidates without a second bundle
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
2026-11-27 21:36:59 +08:00
cflmy 7db401a836 Revert "ci: protected publish workflow (#10)"
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
This reverts commit 5838ba028e, reversing
changes made to 161600102d.
2026-11-27 20:34:39 +08:00
cflmy 5838ba028e ci: protected publish workflow (#10)
ci/woodpecker/release/release Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/tag/publish Pipeline failed
ci: protected publish workflow (#10)
2026-11-27 19:23:24 +08:00
cflmy a23b7ddb5d ci: add protected component publish workflow and immutable release helpers
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
Vendor the root component-release helpers, add source packaging plus
release-evidence, and split publish (tag/manual) from notify (release event).
2026-11-27 19:22:58 +08:00
marqdo-ci 161600102d ci: notify the root reconcile on a completed release
ci/woodpecker/push/ci Pipeline is pending
ci/woodpecker/pr/ci Pipeline is pending
ci/woodpecker/release/release Pipeline was successful
Release event fast path: validate the secret is present, then ask the root
manual `reconcile` workflow to check the authoritative Gitea release. The call
is only a hint; correctness and lost-notification recovery stay in the root
reconcile cron/script.
2026-11-27 14:18:11 +08:00
marqdo-ci f4e51b504f ci: consume the shared shell CI image
ci/woodpecker/push/ci Pipeline is pending
ci/woodpecker/pr/ci Pipeline is pending
ci/woodpecker/manual/ci Pipeline is pending
2026-11-27 14:03:27 +08:00
marqdo-ci 3f8e591ce5 ci: avoid a shell-variable-looking token in the workflow comment
ci/woodpecker/push/ci Pipeline is pending
ci/woodpecker/pr/ci Pipeline was successful
Woodpecker parses shell-style variables throughout the command strings, including
comments; keep the pinned values literal so pipeline config parsing succeeds.
2026-11-27 13:44:54 +08:00
marqdo-ci 73fcf769c1 ci: keep the pinned archive path literal
Woodpecker expands ${...} in commands, which left the version empty. Use the
exact released archive path/SHA so the unified lane is reproducible.
2026-11-27 13:43:51 +08:00
marqdo-ci f4939c2862 ci: add the unified Woodpecker lane (published CLI/Bundle, one base image)
ci/woodpecker/pr/ci Pipeline is pending
ci/woodpecker/push/ci Pipeline failed
ci/woodpecker/manual/ci Pipeline is pending
Reuse the released marqdo rc.5 archive and Bundle with a pinned SHA-256 in
ubuntu:24.04; no Rust toolchain download, no CLI build, no sibling checkout.
This keeps component CI independent and cheap while testing the real CLI.
2026-11-27 13:37:41 +08:00
marqdo-norms 5b5d3b67c3 docs: adopt the ecosystem repository development conventions
Add the repository AGENTS.md boundary and anti-bloat rules required by
marqdo docs/REPOSITORY-CONVENTIONS.md, with the marker and canonical link so
scripts/check-repo-conventions.py can enforce it.
2026-11-27 11:36:21 +08:00
cflmy c2a7d327e5 test: resolve $MARQDO_BIN placeholder in case args and env
Keeps the process self-test usable for any verified CLI identity without
recording a machine-specific absolute path in the repository.
2026-11-26 23:13:32 +08:00
cflmy e15256300f migrate: own the text and UTF-8 sources and their baseline assertions
Move the official stdlib text modules to their unique source authority and
freeze the bundle-root paths (std:text, std:text/utf8). text.utf8编码 becomes a
thin wrapper over the single UTF-8 implementation in text/utf8.mq.md.

Carry the pre-migration product assertions into component-owned cases with the
baseline observation terminal values, plus an explicit-input test entry point
(MARQDO_BIN + MARQDO_STDLIB_DIR). No parser, host or CLI change.

Refs cflmy/marqdo#9, cflmy/marqdo-std-text#1
2026-11-26 23:10:18 +08:00
14 changed files with 719 additions and 6 deletions

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
# Unified Woodpecker CI for a source-only Marqdo component.
#
# The published `marqdo-ci-shell` image is the only runtime dependency: one
# Ubuntu 24.04 base, the released CLI/Bundle, and common test tools. No image
# variance, apt install, Rust toolchain download, CLI rebuild or sibling checkout.
when:
- event: [pull_request, manual]
- event: push
branch: main
steps:
test:
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.5
commands:
- sh scripts/test.sh
- |
set -eu
out=$(mktemp -d)
trap 'rm -rf -- "$out"' EXIT
archive=$(sh scripts/package.sh "$out")
(cd "$out" && sha256sum -c "$(basename "$archive").sha256")
git rev-parse HEAD
cat "$archive.sha256"
+18
View File
@@ -0,0 +1,18 @@
# Fast-path notification: a completed Gitea release asks the root reconcile
# workflow to check it. The payload is only a hint; the root reconcile verifies
# the release/assets from the authoritative Gitea API. A lost call is recovered
# by the root `release-reconcile` cron.
when:
event: [release]
steps:
notify:
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.5
environment:
WOODPECKER_TOKEN:
from_secret: woodpecker_token
commands:
- |
set -eu
test -n "${WOODPECKER_TOKEN:?woodpecker_token secret missing}"
curl -fsS -X POST -H "Authorization: Bearer $WOODPECKER_TOKEN" -H "Content-Type: application/json" -d '{"branch":"main","workflow":"reconcile"}' https://ci.cflmy.cn/api/repos/6/pipelines
+37
View File
@@ -0,0 +1,37 @@
<!-- marqdo:repo-conventions v1 -->
# AGENTS.md — std-text
全局规范唯一来源:[marqdo 仓库开发规范](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/REPOSITORY-CONVENTIONS.md)。本文件只写本仓边界,不复制全局规范或合同正文。
## 1. 本仓定位与唯一权威
- catalog ID:`std-text`;父级:根;角色:stdlib;状态:active。
- 职责/本仓拥有:Unicode 文本、字节值与 UTF-8;唯一模块源码
- 本仓不拥有:CLI 语法/运行时、Bundle 打包实现、其它 stdlib 模块的算法或序列化
- 权威输入/合同:真实 CLI `MARQDO_BIN` + 显式 `MARQDO_STDLIB_DIR` Bundle 的公开模块接口;根 Bundle 生产者
## 2. 必做 / 禁止
| 必做 | 禁止 |
| --- | --- |
| 只在本仓职责内修改,先开本仓工单 | 实现其它仓库功能,复制 parser/实现/合同 |
| 用真实 CLI/制品与独立期望测试 | mock、字符串检查或原型冒充真实验收/PASS |
| 依赖使用固定 SHA/摘要与显式输入 | 依赖父仓 checkout、兄弟仓相对路径、浮动分支 |
| 未运行写 `UNVERIFIED` | 伪造 entry/版本/CI 徽章/gitlink/发布资产 |
| 记录 SHA、制品摘要、平台、命令、退出码 | 提交密钥、凭证、构建产物或本地绝对路径 |
| 跨仓变更走 C2 → B2 → A2 晋升 | 自动 tag/release/合并,或直接改父仓/兄弟仓 |
- 不新增第二 catalog/manifest/lock/版本表/发布流程;不为单功能拆仓或建空壳仓。
- 不在本仓登记其它仓库后代路径;治理树最多两级 gitlink。
## 3. 构建、测试与证据
- CI/验收入口:`scripts/test.sh`(非交互、失败非零、不打印秘密、只写声明输出;构建与发布权限分离)。
- 输入与依赖:真实 CLI `MARQDO_BIN` + 显式 `MARQDO_STDLIB_DIR` Bundle 的公开模块接口;根 Bundle 生产者
- 交付:唯一模块源码 + 断言 + 确定性源码归档/证据(不强制二进制)
- 证据:候选 SHA、依赖/制品 SHA-256、平台/工具链、命令与退出码、日志位置、测试范围;FAIL/UNVERIFIED 不得写成 PASS。
## 4. 工单路由
- 语言/模块加载/Bundle 协议 → `marqdo-cli`;Bundle 装配/路径 → 根 Bundle 生产者;模块语义 → 本仓。
- 模块边界按迁移台账;不复制其它 stdlib 的算法或序列化实现。
+35 -5
View File
@@ -1,14 +1,44 @@
# marqdo-std-text # marqdo-std-text
本仓负责Unicode 文本、字节值与 UTF-8。当前状态为 `planned`。 本仓负责 Unicode 文本、字节值与 UTF-8,已作为 active 标准库组件接入根仓。迁移与验收证据见 [marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9) 和 [本仓 #1](https://git.cflmy.cn/cflmy/marqdo-std-text/issues/1)。
## 首项任务 ## 唯一公开入口(Bundle 根相对路径)
统一 Unicode 文本、字节值切片和 UTF-8 编解码。 | 发布路径 | 公开导入 | 职责 |
| --- | --- | --- |
| `text/utf8.mq.md` | `std:text/utf8` | UTF-8 编解码的**唯一**实现 |
| `text.mq.md` | `std:text` | `utf8编码` 的公开名称,薄封装调用 `std:text/utf8`,不复制算法 |
`modules/` 保存将来 Bundle 根下的相对路径;Bundle 与 `stdlib.json` 由父仓唯一生产者生成,本仓不维护第二份官方 manifest。
## 目录 ## 目录
- [modules/](modules/README.md) 存放对外发布的模块源码。 - `modules/`:对外发布的模块源码(Bundle 根相对路径)。
- [tests/](tests/README.md) 存放独立验收用的输入和断言。 - `tests/`:迁移期保留的 `.mq.md` 自测源与 `tests/cases/` 期望(observation 终值、stdout、参数、环境)。
- `scripts/`:独立验收入口。
## 独立验收
只接受显式传入的已验证制品,不读取兄弟仓物理路径或浮动分支:
```sh
MARQDO_BIN=/path/to/verified/marqdo \
MARQDO_STDLIB_DIR=/path/to/installed/bundle \
scripts/test.sh
```
- `MARQDO_BIN`:真实 CLI 二进制;`MARQDO_STDLIB_DIR`:已安装且通过 manifest digest 校验、包含本仓模块的 Bundle。
- `tests/cases/*.json` 的期望值来自迁移前 CLI Bundle 基线的真实执行结果;修改期望值等于声明公开行为变化,必须单独评审。
- 测试覆盖 UTF-8 字节序列、中文/多字节/emoji、空串和边界 Memory;非法 UTF-8 行为以基线断言为准。
## 边界
本仓拥有文本和 UTF-8 的模块源码及断言。根仓依据精确 gitlink 装配唯一官方 Bundle。使用干净检出可在 Linux 生成带完整提交 SHA 的源码归档及校验文件。
```sh
scripts/package.sh "$(mktemp -d)"
```
独立 CI 在 PR、`main` 推送和手动运行时检验真实 CLI 行为与归档摘要。正式发版走生态受保护发布流程。
[生态迁移台账](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/MIGRATION.md) · [开发流程](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/DEVELOPMENT.md) [生态迁移台账](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/MIGRATION.md) · [开发流程](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/DEVELOPMENT.md)
+13
View File
@@ -0,0 +1,13 @@
---
import:
utf8: "./text/utf8.mq.md"
---
# @exec text
## utf8编码
`params(文本, 内存, 基址)`
把 Unicode 标量序列按 UTF-8 写入 Memory,返回字节长度。
`return utf8.编码(文本, 内存, 基址)`
+258
View File
@@ -0,0 +1,258 @@
# @exec utf8
## 成功
`params(值)`
`return {ok: true, value: 值}`
## 失败
`params(代码, 消息)`
`return {ok: false, code: 代码, message: 消息}`
## 续字节
`params(字节)`
`return 字节 >= 128 and 字节 < 192`
## 编码
`params(文本, 内存, 基址)`
把 Unicode 标量序列按 UTF-8 写入 Memory,返回字节长度。
这是 .mq.md 自己实现的编码逻辑,不是 Rust 内建 UTF-8 转换。
**点 = text.codepoints(文本)**
**下标 = 0**
**偏移 = 0**
`while 下标 < 长度(点)`
**码点 = 点[下标]**
`if 码点 < 128`
**`内存[基址 + 偏移] = 码点`**
**偏移 = 偏移 + 1**
`else`
`if 码点 < 2048`
**`内存[基址 + 偏移] = 192 + 码点 // 64`**
**`内存[基址 + 偏移 + 1] = 128 + 码点 % 64`**
**偏移 = 偏移 + 2**
`else`
`if 码点 < 65536`
**`内存[基址 + 偏移] = 224 + 码点 // 4096`**
**`内存[基址 + 偏移 + 1] = 128 + 码点 // 64 % 64`**
**`内存[基址 + 偏移 + 2] = 128 + 码点 % 64`**
**偏移 = 偏移 + 3**
`else`
`if true`
**`内存[基址 + 偏移] = 240 + 码点 // 262144`**
**`内存[基址 + 偏移 + 1] = 128 + 码点 // 4096 % 64`**
**`内存[基址 + 偏移 + 2] = 128 + 码点 // 64 % 64`**
**`内存[基址 + 偏移 + 3] = 128 + 码点 % 64`**
**偏移 = 偏移 + 4**
`end`
`end`
`end`
`end`
**下标 = 下标 + 1**
`end`
`return 偏移`
## 解码2
`params(内存, 基址, 长度, 偏移, 文本)`
`if 偏移 + 1 >= 长度`
`return [文本, 偏移, "utf8.truncated"]`
`end`
**b1 = 内存[基址 + 偏移 + 1]**
`if not 续字节(b1)`
`return [文本, 偏移, "utf8.invalid_continuation"]`
`end`
**码点 = (内存[基址 + 偏移] - 192) * 64 + (b1 - 128)**
`if 码点 < 128`
`return [文本, 偏移, "utf8.invalid_scalar"]`
`end`
`return [文本 + text.from_codepoint(码点), 偏移 + 2, ""]`
## 解码3
`params(内存, 基址, 长度, 偏移, 文本)`
`if 偏移 + 2 >= 长度`
`return [文本, 偏移, "utf8.truncated"]`
`end`
**b1 = 内存[基址 + 偏移 + 1]**
**b2 = 内存[基址 + 偏移 + 2]**
`if not (续字节(b1) and 续字节(b2))`
`return [文本, 偏移, "utf8.invalid_continuation"]`
`end`
**码点 = (内存[基址 + 偏移] - 224) * 4096 + (b1 - 128) * 64 + (b2 - 128)**
`if 码点 < 2048 or (码点 >= 55296 and 码点 <= 57343)`
`return [文本, 偏移, "utf8.invalid_scalar"]`
`end`
`return [文本 + text.from_codepoint(码点), 偏移 + 3, ""]`
## 解码4
`params(内存, 基址, 长度, 偏移, 文本)`
`if 偏移 + 3 >= 长度`
`return [文本, 偏移, "utf8.truncated"]`
`end`
**b1 = 内存[基址 + 偏移 + 1]**
**b2 = 内存[基址 + 偏移 + 2]**
**b3 = 内存[基址 + 偏移 + 3]**
`if not (续字节(b1) and 续字节(b2) and 续字节(b3))`
`return [文本, 偏移, "utf8.invalid_continuation"]`
`end`
**码点 = (内存[基址 + 偏移] - 240) * 262144 + (b1 - 128) * 4096 + (b2 - 128) * 64 + (b3 - 128)**
`if 码点 < 65536 or 码点 > 1114111`
`return [文本, 偏移, "utf8.invalid_scalar"]`
`end`
`return [文本 + text.from_codepoint(码点), 偏移 + 4, ""]`
## 解码
`params(内存, 基址, 长度)`
**偏移 = 0**
**文本 = ""**
**错误 = ""**
`while 偏移 < 长度 and 错误 == ""`
**首 = 内存[基址 + 偏移]**
`if 首 < 128`
**文本 = 文本 + text.from_codepoint(首)**
**偏移 = 偏移 + 1**
`else`
`if 首 < 194`
**错误 = "utf8.invalid_lead"**
`else`
`if 首 < 224`
**结果 = 解码2(内存, 基址, 长度, 偏移, 文本)**
**文本 = 结果[0]**
**偏移 = 结果[1]**
**错误 = 结果[2]**
`else`
`if 首 < 240`
**结果 = 解码3(内存, 基址, 长度, 偏移, 文本)**
**文本 = 结果[0]**
**偏移 = 结果[1]**
**错误 = 结果[2]**
`else`
`if 首 < 245`
**结果 = 解码4(内存, 基址, 长度, 偏移, 文本)**
**文本 = 结果[0]**
**偏移 = 结果[1]**
**错误 = 结果[2]**
`else`
`if true`
**错误 = "utf8.invalid_lead"**
`end`
`end`
`end`
`end`
`end`
`end`
`end`
`if 错误 == ""`
`return 成功(文本)`
`else`
`if true`
`return 失败(错误, "UTF-8 解码失败")`
`end`
`end`
## utf8编码
`params(文本, 内存, 基址)`
`return 编码(文本, 内存, 基址)`
## utf8解码
`params(内存, 基址, 长度)`
`return 解码(内存, 基址, 长度)`
+32
View File
@@ -0,0 +1,32 @@
#!/bin/sh
# Build a repeatable source archive from this component's clean Git commit.
set -eu
if [ "$#" -ne 1 ]; then
echo "usage: scripts/package.sh OUTPUT_DIRECTORY" >&2
exit 2
fi
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
source=$(git -C "$root" rev-parse --verify HEAD)
if [ -n "$(git -C "$root" status --porcelain)" ]; then
echo "package: source checkout has uncommitted changes" >&2
exit 1
fi
output=$(realpath -m -- "$1")
case "$output/" in
"$root/"*) echo "package: use an output directory outside the source checkout" >&2; exit 2 ;;
esac
mkdir -p -- "$output"
work=$(mktemp -d "$output/.std-text.XXXXXX")
trap 'rm -rf -- "$work"' EXIT
name="marqdo-std-text-$source"
archive="$name-source.tar.gz"
# Keep the operations separate so a failed git archive cannot be masked by gzip.
git -C "$root" archive --format=tar --prefix="$name/" "$source" > "$work/source.tar"
gzip -n < "$work/source.tar" > "$work/$archive"
(cd "$work" && sha256sum "$archive" > "$archive.sha256")
mv -- "$work/$archive" "$work/$archive.sha256" "$output/"
printf '%s\n' "$output/$archive"
+207
View File
@@ -0,0 +1,207 @@
#!/usr/bin/env python3
"""Run this component's public `.mq.md` self-tests against a real CLI Bundle.
Inputs are explicit and never discovered from sibling checkouts:
* ``MARQDO_BIN`` verified ``marqdo`` executable;
* ``MARQDO_STDLIB_DIR`` Bundle that already installs this component's modules at
their frozen bundle paths (the Bundle identity is the caller's responsibility;
the CLI itself verifies the manifest digest before loading a module).
Each ``tests/cases/*.json`` file pins one self-test: the source file, stdin, CLI
flags, environment, the expected bundle module path and the expected observation
terminal value / stdout. The expected values are the baseline captured from the
pre-migration CLI Bundle; a change is a public behaviour change and must be
reviewed as one.
Usage: scripts/test.sh [CASE_NAME...]
"""
from __future__ import annotations
import argparse
import base64
import json
import os
import shutil
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
CASES = REPO / "tests" / "cases"
SCHEMA = "marqdo.stdlib-test-case"
SCHEMA_VERSION = 1
class CaseError(Exception):
pass
def _substitute(value, bin_version: str):
if isinstance(value, dict):
if set(value) == {"$bin_version"}:
return bin_version
return {key: _substitute(item, bin_version) for key, item in value.items()}
if isinstance(value, list):
return [_substitute(item, bin_version) for item in value]
return value
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 CaseError(f"{channel} byte_count does not match decoded bytes")
chunks.append(data)
return b"".join(chunks).decode("utf-8")
def _run_case(case: dict, case_path: Path, binary: str, bundle: Path) -> None:
name = case["name"]
module = case.get("require_module")
if module and not (bundle / module).is_file():
raise CaseError(f"{name}: Bundle {bundle} does not install {module}")
source = REPO / "tests" / case["file"]
if not source.is_file():
raise CaseError(f"{name}: missing test source {source}")
for relative in case.get("clean", []):
target = (REPO / relative).resolve()
if REPO not in target.parents:
raise CaseError(f"{name}: clean path escapes the repository")
if target.is_dir():
shutil.rmtree(target)
elif target.exists():
target.unlink()
env = os.environ.copy()
env["MARQDO_STDLIB_DIR"] = str(bundle)
for key, value in case.get("env", {}).items():
env[key] = str(value).replace("$MARQDO_BIN", binary)
version = subprocess.run(
[binary, "--version"], capture_output=True, text=True, check=True
).stdout
args = [str(arg).replace("$MARQDO_BIN", binary) for arg in case.get("args", [])]
command = [binary, "run", str(source), *args, "--output", "json"]
result = subprocess.run(
command,
cwd=REPO,
env=env,
input=case.get("stdin", "").encode(),
capture_output=True,
)
if result.returncode != 0:
raise CaseError(
f"{name}: CLI exited {result.returncode}\nstderr:\n"
f"{result.stderr.decode(errors='replace')}"
)
try:
report = json.loads(result.stdout)
except json.JSONDecodeError as error:
raise CaseError(f"{name}: CLI did not emit a JSON report: {error}") from error
if report.get("run", {}).get("status") != "ok":
raise CaseError(f"{name}: run status is not ok: {report.get('run')}")
events = report.get("events") or []
if not events or events[-1].get("kind") not in (
"run.completed",
"run.failed",
"run.rejected",
):
raise CaseError(f"{name}: report has no terminal event")
terminal = events[-1]["payload"]
if terminal.get("status") != "ok":
raise CaseError(f"{name}: terminal status is not ok: {terminal.get('status')}")
actual_value = terminal.get("value")
expected_value = _substitute(case["expected_terminal"], version)
if actual_value != expected_value:
raise CaseError(
f"{name}: terminal value changed\nexpected: "
f"{json.dumps(expected_value, ensure_ascii=False, sort_keys=True)}\n"
f"actual: {json.dumps(actual_value, ensure_ascii=False, sort_keys=True)}"
)
expected_stdout = case.get("expected_stdout", "")
actual_stdout = _channel_text(events, "stdout.chunk")
if actual_stdout != expected_stdout:
raise CaseError(
f"{name}: stdout changed: expected {expected_stdout!r}, got {actual_stdout!r}"
)
for check in case.get("event_checks", []):
matching = [
event
for event in events
if event.get("kind") == check["kind"]
and all(
_dig(event.get("payload"), pointer) == expected
for pointer, expected in check.get("payload", {}).items()
)
]
if not matching:
raise CaseError(
f"{name}: no {check['kind']} event matched {check.get('payload')}"
)
def _dig(value, pointer: str):
current = value
for part in pointer.split("."):
if isinstance(current, list):
current = current[int(part)]
elif isinstance(current, dict):
current = current[part]
else:
return object()
return current
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("cases", nargs="*", help="case names to run")
args = parser.parse_args()
binary = os.environ.get("MARQDO_BIN")
bundle = os.environ.get("MARQDO_STDLIB_DIR")
if not binary or not shutil.which(binary):
print("MARQDO_BIN must point at a verified marqdo executable", file=sys.stderr)
return 2
if not bundle or not Path(bundle).is_dir():
print("MARQDO_STDLIB_DIR must point at an installed Bundle", file=sys.stderr)
return 2
bundle = Path(bundle).resolve()
paths = sorted(CASES.glob("*.json"))
if not paths:
print("no test cases in tests/cases", file=sys.stderr)
return 2
selected = set(args.cases)
failures = 0
ran = 0
for path in paths:
try:
case = json.loads(path.read_text(encoding="utf-8"))
except json.JSONDecodeError as error:
print(f"FAIL {path.name}: invalid JSON: {error}", file=sys.stderr)
failures += 1
continue
if case.get("schema") != SCHEMA or case.get("schema_version") != SCHEMA_VERSION:
print(f"FAIL {path.name}: unsupported case schema", file=sys.stderr)
failures += 1
continue
if selected and case["name"] not in selected:
continue
ran += 1
try:
_run_case(case, path, binary, bundle)
print(f"PASS {case['name']}")
except CaseError as error:
print(f"FAIL {error}", file=sys.stderr)
failures += 1
if failures:
print(f"{failures} of {ran} cases failed", file=sys.stderr)
return 1
print(f"{ran} cases passed")
return 0
if __name__ == "__main__":
sys.exit(main())
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
# Explicit inputs only: a verified CLI binary and a Bundle that installs this
# component's modules at their frozen paths. Never discovers sibling checkouts.
set -eu
: "${MARQDO_BIN:?set MARQDO_BIN to the verified marqdo executable}"
: "${MARQDO_STDLIB_DIR:?set MARQDO_STDLIB_DIR to the installed Bundle}"
exec python3 "$(dirname "$0")/run_cases.py" "$@"
+5 -1
View File
@@ -1,3 +1,7 @@
# 验收测试 # 验收测试
首个功能附带正例和失败用例,记录所用 CLI 提交或发行版本以及实际运行命令。 `tests/*.mq.md` 是从迁移前 CLI 官方标准库自测迁入的真实测试源;`tests/cases/*.json` 固定每个测试的输入(stdin、CLI 参数、环境、所需 Bundle 模块)和期望结果(observation 终值、stdout、必要的资源事件)。
运行入口是 `scripts/test.sh`,它要求显式传入 `MARQDO_BIN` 与 `MARQDO_STDLIB_DIR`。缺少制品、Bundle 缺少模块或 digest 校验失败时必须失败,不得回退到其它目录。
期望值取自迁移前基线 CLI 的真实执行结果;任何期望值改动都必须作为公开行为变化单独评审并记录证据。
+28
View File
@@ -0,0 +1,28 @@
{
"schema": "marqdo.stdlib-test-case",
"schema_version": 1,
"name": "text",
"file": "text.mq.md",
"require_module": "text.mq.md",
"args": [],
"stdin": "",
"env": {},
"expected_stdout": "",
"expected_terminal": {
"items": [
{
"decimal": "2",
"type": "int"
},
{
"decimal": "195",
"type": "int"
},
{
"decimal": "169",
"type": "int"
}
],
"type": "list"
}
}
+28
View File
@@ -0,0 +1,28 @@
{
"schema": "marqdo.stdlib-test-case",
"schema_version": 1,
"name": "utf8",
"file": "utf8.mq.md",
"require_module": "text/utf8.mq.md",
"args": [],
"stdin": "",
"env": {},
"expected_stdout": "",
"expected_terminal": {
"items": [
{
"decimal": "2",
"type": "int"
},
{
"type": "text",
"value": "é"
},
{
"type": "bool",
"value": false
}
],
"type": "list"
}
}
+14
View File
@@ -0,0 +1,14 @@
---
import:
text_lib: "std:text"
---
# @exec text
## main
**内存 = memory.new(1, 1)**
**长度 = text_lib.utf8编码("é", 内存, 0)**
`return [长度, 内存[0], 内存[1]]`
+14
View File
@@ -0,0 +1,14 @@
---
import:
utf8: "std:text/utf8"
---
# @exec utf8
## main
**内存 = memory.new(1, 1)**
**长度 = utf8.编码("é", 内存, 0)**
`return [长度, utf8.解码(内存, 0, 长度).value, utf8.解码(内存, 0, 1).ok]`