概览
每条数据是一项原创的长程开发任务,基于真实且仍在活跃维护的代码库:开发者用一段话提出一项代码库里还没有的功能,Agent 要自己读懂代码库,找出所有该改的地方,跨多个文件完整实现该行为(各条并行路径、默认值、边界和错误情形),最后提交。每条数据包含两部分:一是 DeepSWE 格式的可复跑任务环境(Harbor 任务目录:离线环境的 Dockerfile、需求原文、隐藏测试和参考解),可直接用于强化学习;二是 Claude Opus 5.5(max effort)在 DeepSWE 主榜同款的纯 bash Agent 框架 mini-swe-agent 中解这道题的完整轨迹,附评分结果以及通过或失败的原因,可用于监督微调。
难度与质量
- 难题档:Claude Opus 5.5(max effort)3 次尝试至多解出 1 次。
- 失败出在模型,不在题目:没做对的题,原因都在 Agent 自己,不在题面或评分器。
- 参考解满分:每题附参考解,用 Harbor 的 oracle 运行即得 reward 1.0,可自行复核。
交付内容
tasks/<任务>/ # Harbor 任务目录,可直接用 Harbor 或 Pier 运行
├── task.toml # 元数据、资源、时限;Agent 与评分都断网
├── instruction.md # 需求原文:Agent 收到的唯一输入
├── environment/ # Dockerfile 与构建上下文(固定提交的代码库),构建出含完整工具链的离线镜像
├── tests/ # 隐藏:test.sh、隐藏测试、失败→通过与回归白名单、构建/类型检查门禁
├── solution/ # 参考解:solution.patch、solve.sh
└── requirements.json # 需求逐条 ↔ 检查它的隐藏测试
trials/<任务>__<序号>/
├── agent/
│ ├── requests.jsonl.zst # 请求级 API 记录:每次调用的完整上下文与回复,含思考摘要
│ ├── trajectory.json # 同一条轨迹的 ATIF 格式
│ ├── mini-swe-agent.trajectory.json
│ └── steps.jsonl # 逐步视图:思考摘要、命令、输出
├── artifacts/model.patch # 评分所依据的已提交改动
├── verifier/ # reward.json、ctrf.json、测试输出
├── result.json # 运行摘要:模型调用、命令数、用时
└── audit.json # 通过或失败的原因,逐个失败测试的根因
index.json # 任务与轨迹总览
README.md # 构建、运行和评分说明
用 Harbor 运行
# 跑参考解
harbor run -p tasks -a oracle
# 跑你的 Agent
harbor run -p tasks -a <agent> -m <model>
- 评分:所有失败→通过测试都通过,且回归测试和构建/类型检查无一失败,记 1 分,否则记 0 分;reward.json 另记两类测试各自的通过比例。隐藏测试只通过需求中写明的公开接口做断言;评分时 Agent 自己写的测试文件会先移开。
- 隔离:Agent 断网工作,看不到隐藏测试和参考解;评分时在全新容器中检查已提交的改动。
- 轨迹:每一步含思考摘要、bash 命令及其输出;请求级记录保存每次模型调用的完整上下文。
样例
3 道样题全部来自难题档,覆盖 Python 和 Rust,领域各不相同。参考解新增 553–2,165 行、涉及 13–21 个文件;每题有 188–754 个失败→通过的隐藏测试,另有 807–9,319 个回归测试。
| 样题 | 语言 | 领域 | 参考解 | 失败→通过测试 |
|---|---|---|---|---|
| 1 | Python | ORM 管理后台 | +751 行 / 21 个文件 | 392 |
| 2 | Rust | 授权策略引擎 | +2,165 行 / 13 个文件 | 188 |
| 3 | Python | RDF 图处理库 | +553 行 / 19 个文件 | 754 |
每张卡片给出 Agent 收到的需求原文、难点和隐藏测试检查的内容。
样例 1 / 3
CSV 导入:按 ID 列更新已有行、分批提交与试运行
sqladmin:一个 Python 库,为 Starlette 和 FastAPI 应用提供基于 SQLAlchemy 模型(支持同步与异步引擎)的 Web 管理后台。
现有的 CSV 导入只会插入,把改过的导出文件再导回去,会产生重复行或违反唯一约束。需求新增三项:ModelView.import_id_columns,按这些列用转换后的值查找,恰好匹配一行就更新它,没有匹配就插入;ModelView.import_batch_size,每新建或更新这么多行就提交一次,导入中途停止时保留已提交的批次;导入接口的 dry_run 表单字段,试运行做同样的校验、查找、权限检查和逐行 flush,但什么都不提交,报告须与真实导入完全一致。每个 result 事件还要新增 created、updated 和 dry_run,导入弹窗要加一个 dry_run 复选框,并显示新建和更新的行数。
难在哪里
- 试运行什么都不提交,却要报告与相同
import_batch_size的真实导入完全相同的结果,包括真实导入停止前已分批保存的行数,以及靠逐行 flush 才暴露的约束冲突。 - 只有成功新建或更新的行计入批次;因行失败、客户端断开或提交失败而停止时,只回滚未提交的部分,计数和摘要只算已提交的批次,一行都没提交时须与不分批的结果完全相同。
- 查找用转换后的值(
yes要匹配存储的True),布尔 ID 列的空单元格会被转成False,但仍算缺失;行按文件顺序生效,后面的行要能匹配前面刚新建、刚更新或更早批次已提交的行。 add_view()要按最终生效的导入列校验(未设column_import_list时退回column_list,再退回主键),import_batch_size要拒绝bool、浮点数、字符串和None,正值还须配合import_id_columns。- 改动横跨导入流程、配置校验、结果事件和导入弹窗的模板与脚本,而进度事件、上传校验错误、原有结果字段和真实导入的摘要须一字不变,同步与异步引擎表现一致。
需求原文(Agent 收到的唯一输入)
CSV import can only insert, so re-importing an edited export duplicates rows or breaks unique constraints.
Add ModelView.import_id_columns: ClassVar[list[str | InstrumentedAttribute]] = []. Entries (attributes or names) must be mapped columns, not relationships, in the resolved column_import_list; otherwise Admin.add_view() raises sqladmin.exceptions.ImproperlyConfigured. When the list is empty, nothing changes. Otherwise, each valid row with a value in every id column (an empty cell counts as missing) is looked up by equality on those columns using its coerced values. Rows missing an id value or a match are inserted. A row with exactly one match updates it with the row's import-column values (empty nullable cells set NULL, as on insert) and counts as updated even if nothing changed. Rows apply in file order, so a row can match one created or updated by an earlier row, in any batch. Updates (not inserts) also require can_edit and await check_can_edit(request, existing_obj). A refused update or a multi-row match fails like other persistence failures (aborting the import, or skipped with continue_on_error), with a non-empty errors["__all__"] list in its missed_rows entry. on_import_row(data, model, request) also runs for updates, with the existing instance as model. Rows absent from the file are untouched, and on_model_change/after_model_change aren't called. Every result event, aborts included, gains created (int), updated (int) and dry_run (bool), with imported always equal to created + updated.
Add ModelView.import_batch_size: ClassVar[int] = 0, a non-negative int (not a bool) that may be positive only with import_id_columns; otherwise add_view() raises ImproperlyConfigured. A positive value commits whenever that many rows have been created or updated since the last commit (failed rows don't count), and commits the rest at the end; 0 keeps one transaction. An import that stops early, for any reason, rolls back only what isn't committed. Aborted results keep ok: false, aborted: true, rolled_back: true and today's skipped/missed_rows, but imported, created and updated count the rows of committed batches. When that count is non-zero, the summary keeps its first sentence but ends with <N> row(s) were saved before the import stopped. (<N> = imported) instead of saying no rows were imported.
POST {base_url}/{identity}/import accepts a dry_run form field parsed exactly like continue_on_error. A dry run does the same validation, lookups, permission checks, on_import_row calls and per-row flushes (so constraint violations become row failures) but commits nothing. It reports exactly what a real run with the same import_batch_size would, aborts included, except for dry_run: true and a Dry run: summary prefix. The import modal gets a name="dry_run" checkbox sent with the upload and shows the created/updated counts.
Progress events, upload-validation error responses, existing result keys and non-dry-run summaries are otherwise unchanged, and sync and async engines behave identically.
IMPORTANT: Please work on this in a new branch from main and commit everything when you are done.
需求的中文大意
CSV 导入只能插入,所以把修改过的导出文件重新导入,会产生重复行或违反唯一约束。
新增 ModelView.import_id_columns: ClassVar[list[str | InstrumentedAttribute]] = []。其中的条目(属性或名称)必须是已映射的列(不能是关系),并且在最终生效的 column_import_list 中,否则 Admin.add_view() 抛出 sqladmin.exceptions.ImproperlyConfigured。列表为空时一切照旧。否则,每个有效行只要在每个 ID 列上都有值(空单元格视为缺失),就用它转换后的值在这些列上按相等条件查找。缺少 ID 值或找不到匹配的行会被插入。恰好匹配一行时,用该行各导入列的值更新匹配到的记录(与插入时一样,可空列的空单元格设为 NULL),即使没有任何变化也计为已更新。各行按文件顺序生效,因此一行可以匹配到前面的行新建或更新的记录,无论在哪个批次。更新(而非插入)还要求 can_edit 和 await check_can_edit(request, existing_obj) 都为真。被拒绝的更新或匹配到多行的行,与其他持久化失败一样处理(中止导入,或在 continue_on_error 时跳过),其 missed_rows 条目中带有非空的 errors["__all__"] 列表。on_import_row(data, model, request) 在更新时也会运行,model 为已有实例。文件中没有的行保持不变,也不调用 on_model_change / after_model_change。每个 result 事件(包括中止时的)都新增 created(int)、updated(int)和 dry_run(bool),且 imported 始终等于 created + updated。
新增 ModelView.import_batch_size: ClassVar[int] = 0,取值为非负 int(不能是 bool),只有设置了 import_id_columns 时才能为正;否则 add_view() 抛出 ImproperlyConfigured。取正值时,每当自上次提交以来新建或更新的行数达到该值就提交一次(失败的行不计入),剩下的在结束时提交;为 0 时保持单个事务。导入无论因何提前停止,都只回滚尚未提交的部分。中止时的结果仍为 ok: false、aborted: true、rolled_back: true,skipped 和 missed_rows 也与现在相同,但 imported、created 和 updated 计入已提交批次中的行。该计数不为零时,摘要保留第一句,但结尾改为 <N> row(s) were saved before the import stopped.(<N> 即 imported),不再说没有导入任何行。
POST {base_url}/{identity}/import 接受表单字段 dry_run,解析方式与 continue_on_error 完全相同。试运行执行同样的校验、查找、权限检查、on_import_row 调用和逐行 flush(因此违反约束会成为该行的失败),但什么都不提交。它的报告与相同 import_batch_size 的真实导入完全一致(中止时也一样),区别只在于带有 dry_run: true,且摘要加上前缀 Dry run: 。导入弹窗新增一个 name="dry_run" 的复选框,随上传一起提交,并显示新建和更新的行数。
除此之外,进度事件、上传校验的错误响应、原有的结果字段和非试运行的摘要都保持不变,同步与异步引擎的行为完全相同。
重要:请从 main 新建分支进行这项工作,完成后提交所有改动。
隐藏测试检查什么
- add_view() 时校验配置:import_id_columns(默认“[]”,可写属性或名称)不得含关系、未知名称或不在最终导入列中的列;import_batch_size(默认整数 0)拒绝负数、布尔值、浮点数、字符串、None,以及未设 import_id_columns 时的正数。
- 按转换后的值匹配全部 ID 列(yes、no 对应存储的布尔值),ID 单元格为空就直接插入,不去匹配值为 NULL 的行;恰好匹配一行时用导入列的值更新(空的可空单元格写 NULL,没有变化也算更新),文件中没有的行不动;后面的行能更新前面新建的或更早批次已提交的行。
- 更新须通过 can_edit 和以已有行调用的 check_can_edit(授权后端拒绝编辑时同样拦下),插入不受影响;被拒的更新和匹配到多行的行带非空的 __all__ 错误列表,在 continue_on_error 下被跳过,否则中止导入;on_import_row 在更新时拿到已有实例,on_model_change 和 after_model_change 都不被调用。
- 分批时,每满一批就在处理下一行之前提交,失败的行不计数,余下的在结束时提交;因行失败、客户端断开、批次或最终提交失败而停止时,已提交的批次保留,计数只算这些行,摘要以“N row(s) were saved before the import stopped.”结尾;一行都没提交时,结果与不分批时完全相同。
- dry_run 按 continue_on_error 的规则解析(1、true、on、yes 不分大小写为真,0、off、y、2 等按真实导入);试运行照样检查权限、调用 on_import_row,并把约束冲突(包括与本次前面新建的行冲突)报成行失败,但任何时刻都不提交。
- 试运行的计数、跳过的行和摘要与相同 import_batch_size 的真实导入逐项一致,中途停止和被取消时也一样,只多 dry_run: true 和“Dry run: ”前缀。
- 每个 result 事件(含中止和取消)都有整数 created、updated 和布尔 dry_run,imported 等于两者之和;进度事件、上传校验错误的状态码和文字(试运行时也一样)以及真实导入的摘要与原来逐字相同。
- 在列表页上像用户一样操作导入弹窗:勾选 dry_run 复选框则试运行,勾上再取消则真实导入,与 continue_on_error 同时勾选时两者都随上传发送,弹窗显示新建和更新的行数;检查覆盖同步与异步引擎,807 个已有测试须继续通过,且包仍须能构建并通过 mypy 检查。
- 失败→通过测试
- 392
- 回归测试
- 807
- 构建/类型检查
- 2
- 参考解改动文件
- 21
- 参考解新增行
- +751
样例 2 / 3
为 Cedar 增加逐条策略的授权解释,并定位未通过条件的源码范围
Cedar:实现 Cedar 授权策略语言的 Rust workspace,包含解析器、求值器、授权器、校验器、格式化工具、CLI 以及 JSON/wasm FFI。
针对每条策略,报告各 scope 约束是否匹配、哪个 when / unless 子句(如有)使其不成立或出错,以及该策略是否决定了最终决策。对于停在某个子句上的策略,还要给出该子句条件的字节范围:偏移口径与求值错误的源码位置相同,模板链接策略指向模板文本,不是从 Cedar 文本解析来的策略没有范围。这些结果通过 Authorizer::explain、cedar authorize --explain 和 JSON/wasm FFI 函数提供,CLI 还要把范围起点换算成行号和按字符计的列号;现有行为保持不变。
难在哪里
- 核心 AST 把所有
when/unless子句折叠成一个表达式,子句边界没有保留,因此读不出索引,也读不出条件范围。 - 范围要覆盖写出来的整个条件:只去掉两侧的空白和注释,外层括号和内部注释都要保留,字符串或注解里的
}、//等文本也不能干扰定位。 - 同一位置有两套坐标:API 和 FFI 用字节偏移,从解析文本开头算起,模板链接策略落在模板文本中;CLI 用从 1 开始的行号和按字符计的列号。遇到多字节字符时,两者的计数不再相同。
- 每个 scope 约束需结合模板 slot 值单独判断,涵盖
==、in、is、is ... in和 action 列表,任一不匹配就要跳过条件;子句求值在第一个不通过的子句处停止,unless判定取反,运行时错误和非布尔结果都要报告为Error。 - 需求横跨 Rust API、CLI、JSON FFI 和
cedar-wasm,各处报告必须一致,同时现有is_authorized结果、CLI 输出字节和退出码都不得改变。
需求原文(Agent 收到的唯一输入)
is_authorized can't say why a policy didn't apply. Keeping existing behaviour unchanged, add Authorizer::explain(&self, &Request, &PolicySet, &Entities) -> AuthorizationExplanation and cedar_policy root types:
AuthorizationExplanation:response() -> &Responseanddecision() -> Decision(same asis_authorized),policies() -> impl Iterator<Item = &PolicyExplanation>(static and template-linked policies sorted by ID string),policy(&PolicyId) -> Option<&PolicyExplanation>.PolicyExplanation:id() -> &PolicyId,effect() -> Effect,outcome() -> PolicyOutcome,condition_index() -> Option<usize>,condition_range() -> Option<std::ops::Range<usize>>,boolgettersprincipal_matched(),action_matched(),resource_matched(),is_determining()(iff the ID is inresponse().diagnostics().reason()).PolicyOutcome(derivesDebug, Clone, Copy, PartialEq, Eq):NotApplicable,ConditionFalse,Satisfied,Error.
All scope flags are always computed, each on its own (links use slot values); any false gives NotApplicable with no condition evaluated. Otherwise when/unless clauses are evaluated in source order until one doesn't pass (when needs true, unless false): Error if it errored or wasn't boolean, else ConditionFalse; Satisfied if none does. For ConditionFalse/Error only (else None), condition_index() is that clause's 0-based index and condition_range() the byte range of its condition inside the braces, minus surrounding whitespace and comments, in the same offsets as the policy's evaluation-error source locations (for linked policies, into the template's text); the range is also None if the policy (or its template) wasn't parsed from Cedar text.
cedar authorize --explain prints the normal output, a blank line, explanation:, then per policy in ID order <id> (<permit|forbid>): <text>, <text> being satisfied (determining), satisfied, scope did not match: <parts> (non-matching of principal, action, resource, in order, joined by , ), condition <i> not satisfied or error in condition <i> (<i> = condition_index()); if the range is known, the last two gain (line <l>, column <c>), the range start's 1-based line and character-counted column in the policies input. Exit codes don't change.
In cedar_policy::ffi add explain_authorization(AuthorizationCall) -> ExplanationAnswer, explain_authorization_json and explain_authorization_json_str (typed like their is_authorized counterparts; Err only for input that isn't an AuthorizationCall), and a wasm_bindgen export explainAuthorization (feature wasm) re-exported by cedar-wasm. Unparseable inputs give is_authorized's failure answer. Success is is_authorized's success answer plus "policies":[...]: ffi::PolicyExplanation objects, with condition_range(&self) -> Option<ffi::SourceLocation>, in policies() order, each with exactly id, effect ("permit"/"forbid"), principalMatched, actionMatched, resourceMatched, outcome (camelCase variant), determining, conditionIndex and conditionRange ({"start":s,"end":e}), the last two null when absent.
IMPORTANT: Please work on this in a new branch from main and commit everything when you are done.
需求的中文大意
is_authorized 说不出某条策略为什么没有生效。在保持现有行为不变的前提下,新增 Authorizer::explain(&self, &Request, &PolicySet, &Entities) -> AuthorizationExplanation,并在 cedar_policy 根模块新增以下类型:
AuthorizationExplanation:response() -> &Response和decision() -> Decision(与is_authorized相同)、policies() -> impl Iterator<Item = &PolicyExplanation>(静态策略和模板链接策略,按 ID 字符串排序)、policy(&PolicyId) -> Option<&PolicyExplanation>。PolicyExplanation:id() -> &PolicyId、effect() -> Effect、outcome() -> PolicyOutcome、condition_index() -> Option<usize>、condition_range() -> Option<std::ops::Range<usize>>,以及返回bool的 getterprincipal_matched()、action_matched()、resource_matched()、is_determining()(当且仅当该 ID 出现在response().diagnostics().reason()中时为 true)。PolicyOutcome(派生Debug, Clone, Copy, PartialEq, Eq):NotApplicable、ConditionFalse、Satisfied、Error。
所有 scope 标志始终都要计算,且各自单独判断(模板链接使用其 slot 值);任一为 false 时结果为 NotApplicable,且不对任何条件求值。否则按源码顺序依次对 when / unless 子句求值,直到某个子句不通过(when 要求值为 true,unless 要求值为 false):若该子句出错或结果不是布尔值,结果为 Error,否则为 ConditionFalse;如果没有子句不通过,结果为 Satisfied。仅对 ConditionFalse / Error(其他情况为 None),condition_index() 是该子句从 0 开始的索引,condition_range() 是其条件在花括号内的字节范围,不含两侧的空白和注释,偏移口径与该策略求值错误的源码位置相同(模板链接策略的偏移落在模板文本中);如果策略(或其模板)不是从 Cedar 文本解析而来,范围同样为 None。
cedar authorize --explain 先打印正常输出,然后输出一个空行、explanation:,再按 ID 顺序为每条策略输出一行 <id> (<permit|forbid>): <text>。其中 <text> 为 satisfied (determining)、satisfied、scope did not match: <parts>(principal、action、resource 中未匹配的项,按此顺序,用 , 连接)、condition <i> not satisfied 或 error in condition <i>(<i> 即 condition_index());范围已知时,后两种文本再追加 (line <l>, column <c>),即范围起点在策略输入中从 1 开始的行号和按字符计的列号。退出码不变。
在 cedar_policy::ffi 中新增 explain_authorization(AuthorizationCall) -> ExplanationAnswer、explain_authorization_json 和 explain_authorization_json_str(类型与对应的 is_authorized 函数一致;仅当输入不是 AuthorizationCall 时返回 Err),以及一个 wasm_bindgen 导出 explainAuthorization(feature wasm),并由 cedar-wasm 重新导出。无法解析的输入返回与 is_authorized 相同的失败结果。成功结果是 is_authorized 的成功结果再加上 "policies":[...]:其中是 ffi::PolicyExplanation 对象,提供 condition_range(&self) -> Option<ffi::SourceLocation>,按 policies() 的顺序排列,每个对象恰好包含 id、effect("permit" / "forbid")、principalMatched、actionMatched、resourceMatched、outcome(变体名的 camelCase 形式)、determining、conditionIndex 和 conditionRange({"start":s,"end":e}),后两项缺失时为 null。
重要:请从 main 新建一个分支来完成这项工作,完成后提交所有改动。
隐藏测试检查什么
- API 形态:Authorizer::explain、根模块类型及其 getter、PolicyOutcome 的 derive、按 ID 的 policy() 查找,以及解释对象在其策略集释放后仍可使用;policies() 按 ID 字符串排序(区分大小写,含默认的 policyN ID),不列出未链接模板,空策略集无条目。
- 在带错误的允许、forbid 导致的拒绝、默认拒绝和跳过出错 forbid 等场景下,response() 均与 is_authorized 一致,is_determining() 与 reason 一致;is_authorized 自身结果不变。
- 针对“==”、经实体层级的 in、is、is ... in、action 列表和模板 slot 值检查 scope 标志(单项及组合不匹配);不匹配时为 NotApplicable 且不对条件求值。
- 子句结果:when / unless 的通过规则、在第一个不通过的子句处停止、when 和 unless 连续编号的索引、缺失属性与溢出错误、非布尔值,以及 JSON 策略按 conditions 数组的顺序。
- 范围的取值:只有 ConditionFalse 和 Error 才有范围;覆盖整个条件,而不只是出错的部分;去掉两侧空白和注释,保留外层括号、内部注释和换行;字符串里的花括号和注释标记、记录字面量和注解里的花括号都不影响结果。
- 范围的偏移:按字节计,策略前的注释、注解和整个策略集文本都计入,与求值错误的源码位置同一口径,改 ID 后不变;模板链接指向模板文本;JSON、PST 和 protobuf 解码得到的策略没有范围,JSON 模板的链接同样没有。
- CLI:--explain 各行精确,接在含 --verbose 在内的正常输出之后;位置为从 1 开始的行号和按字符计的列号,策略来自文件或 stdin 都成立,JSON 格式的策略不带位置;不带选项时成功和失败输出逐字节不变,退出码不变。
- FFI 与 wasm:顶层字段和每条策略的九个字段都精确,缺失时保留 null;类型化结果的 condition_range() 与 JSON 的 conditionRange 一致;失败结果和 warnings 与 is_authorized 相同;_json 系列函数仅在输入不是 AuthorizationCall 时返回 Err;cedar-wasm 的重新导出同样受检。
- 失败→通过测试
- 188
- 回归测试
- 3,482
- 构建/类型检查
- 1
- 参考解改动文件
- 13
- 参考解新增行
- +2,165
样例 3 / 3
端到端支持 RDF 1.2 基础方向,含 JSON-LD @direction
rdflib:用于处理 RDF 的 Python 库,包含图与 RDF 项(term)模型、N-Triples/Turtle/TriG/N3/JSON-LD 等格式的解析器与序列化器、基于 pyparsing 的 SPARQL 1.1 引擎,以及可插拔的存储后端。
让 RDF 1.2 带方向的语言标签字符串("x"@ar--rtl)端到端可用。范围包括:Literal 增加 direction,N-Triples/Turtle 系列解析器与序列化器,SPARQL 语法及 LANGDIR、hasLANG、hasLANGDIR、STRLANGDIR 函数,SPARQL 结果格式,存储,以及 JSON-LD 的 @direction。解析 JSON-LD 时,值对象只用自身的方向,其他字符串先取术语定义的方向,没有再取上下文默认值;序列化时,只有当裸字符串或语言映射读回的方向与字面量自身相同时才用这种简写,否则写成值对象。不带基础方向的数据,其行为和序列化结果必须与现在完全一致。
难在哪里
Literal、各 RDF 语法的解析器与序列化器、SPARQL 语法与函数、结果格式、存储,以及 JSON-LD 的上下文、解析器和序列化器等多条并行路径须协同一致;参考解涉及 19 个文件。- JSON-LD 解析时方向的来源有固定优先级:值对象即使带语言标签,也只用自身的方向;字符串先取术语定义的方向(定义为
null也算),否则取上下文默认值,与语言标签来自哪里无关;嵌入式和作用域上下文继承默认方向,null上下文将其清除。 - JSON-LD 序列化的输出须能原样读回:裸字符串、语言映射条目和列表项只有在读回的方向与字面量自身相同(都没有方向也算)时才能用,否则写成值对象(上下文为
@direction定义了别名时用别名)。 - 非法方向须在对应位置抛指定异常:RDF 语法中
--后只能是小写的ltr或rtl,nt、nquads 抛ParserError,turtle、trig、n3 抛BadSyntax;JSON-LD 中非法的@direction在加载文档或Context时就要抛JSONLDException,即使从未用到,或所在的值没有语言标签、方向本会被丢弃。 - 不带方向的数据须与现状完全一致(由 9,321 项回归检查把关,含既有测试及构建、类型检查),JSON-LD 的解析与输出也不例外;而相等、哈希与 pickle 都要纳入新字段。
需求原文(Agent 收到的唯一输入)
rdflib handles "x"@ar everywhere; add RDF 1.2 base direction ("x"@ar--rtl, rdf:dirLangString) end to end.
Literal gets a fifth parameter direction=None and a read-only .direction (.datatype stays None); a direction other than 'ltr'/'rtl' raises ValueError (even ''), one without a language tag TypeError. ==, hash and eq() distinguish "x"@ar, "x"@ar--ltr and "x"@ar--rtl. repr() is rdflib.term.Literal('x', lang='ar', direction='rtl'); n3() is "x"@ar--rtl, parsed back by rdflib.util.from_n3; pickle, copy, deepcopy, Literal(lit) and Memory/BerkeleyDB stores (across re-open) preserve it.
The nt/ntriples/nt11, nquads, turtle/ttl, trig and n3 parsers and serializers, plus longturtle, handle it and round-trip; parsing accepts it with subtags (@en-US--ltr) and after every Turtle/TriG string form and N3's double-quoted ones. Only lowercase ltr/rtl may follow --; anything else, or --rtl without a language tag, raises ParserError (nt, nquads) or BadSyntax (turtle, trig, n3).
SPARQL queries and updates accept it wherever a literal may appear. LANGDIR gives "ltr"/"rtl", "" for other literals, an error for IRIs/bnodes; hasLANG/hasLANGDIR give xsd:boolean, true iff given a literal with a tag/direction (never an error); STRLANGDIR("abc", "ar", "rtl") is "abc"@ar--rtl, an error for a bad direction or tagged/typed first argument. DATATYPE("x"@ar--rtl) is rdf:dirLangString (a plain URIRef, not added to rdflib.RDF); LANG gives just the tag. UCASE, LCASE, SUBSTR, STRBEFORE, STRAFTER and REPLACE keep the direction where they keep the tag; CONCAT keeps tag and direction only if all arguments share both, else neither. In SPARQL results, json adds "its:dir": "rtl" beside "xml:lang" and xml a dir attribute in namespace http://www.w3.org/2005/11/its on <literal>, both parsed back; tsv parsing accepts "x"@ar--rtl; txt prints --rtl.
JSON-LD @direction (aliasable like other keywords) maps to Literal.direction: value objects use only their own, other string values their term's if it defines one (even null), else the context default, independent of their language's source. Embedded and scoped contexts inherit the default unless they set one; a null context clears it. Directions on values without a language tag are silently dropped. @direction values other than "ltr", "rtl" or null (none) raise JSONLDException with "invalid base direction" in the message when their document or Context is loaded, even if unused. The serializer adds @direction (or the context's alias) to value objects of directional literals and keeps today's bare-string or language-map form for a language-tagged literal only if the direction that form reads back as (its term's @direction if defined, else the context default) equals the literal's own, absence included; otherwise it writes a value object with @value, @language and any @direction. Context.direction holds the default (None if unset); its terms get a direction field and add_term() a direction argument (UNDEF if not given); to_dict() emits @direction for a set default and each term defining one.
Anything without a base direction must behave and serialize exactly as today.
IMPORTANT: Please work on this in a new branch from main and commit everything when you are done.
需求的中文大意
rdflib 在各处都能处理 "x"@ar;请端到端地加上 RDF 1.2 的基础方向("x"@ar--rtl,rdf:dirLangString)。
Literal 新增第五个参数 direction=None 和只读属性 .direction(.datatype 仍为 None);方向不是 'ltr' 或 'rtl' 时抛出 ValueError('' 也不例外),有方向而没有语言标签时抛出 TypeError。==、哈希和 eq() 都要区分 "x"@ar、"x"@ar--ltr 和 "x"@ar--rtl。repr() 为 rdflib.term.Literal('x', lang='ar', direction='rtl');n3() 为 "x"@ar--rtl,并且 rdflib.util.from_n3 能把它解析回来;pickle、copy、deepcopy、Literal(lit) 以及 Memory 和 BerkeleyDB 存储(重新打开后)都要保留方向。
nt/ntriples/nt11、nquads、turtle/ttl、trig 和 n3 的解析器与序列化器,外加 longturtle,都要能处理它并能往返(round-trip)。解析时要接受带子标签的写法(@en-US--ltr),它可以跟在 Turtle/TriG 的每一种字符串形式之后,也可以跟在 N3 的双引号字符串形式之后。-- 之后只允许小写的 ltr 或 rtl;其他任何内容,或没有语言标签的 --rtl,都要抛出 ParserError(nt、nquads)或 BadSyntax(turtle、trig、n3)。
SPARQL 查询与更新在任何可以出现字面量的位置都要接受它。LANGDIR 返回 "ltr" 或 "rtl",对其他字面量返回 "",对 IRI 和空白节点报错;hasLANG 和 hasLANGDIR 返回 xsd:boolean,当且仅当参数分别是带语言标签、带方向的字面量时为 true(从不报错);STRLANGDIR("abc", "ar", "rtl") 为 "abc"@ar--rtl,方向非法,或第一个参数带语言标签或数据类型时报错。DATATYPE("x"@ar--rtl) 为 rdf:dirLangString(普通 URIRef,不要加入 rdflib.RDF);LANG 只返回标签本身。UCASE、LCASE、SUBSTR、STRBEFORE、STRAFTER 和 REPLACE 在保留标签的地方同样保留方向;CONCAT 仅当所有参数的标签和方向都相同时才保留两者,否则两者都不保留。在 SPARQL 结果中,json 在 "xml:lang" 旁加上 "its:dir": "rtl",xml 给 <literal> 加上命名空间为 http://www.w3.org/2005/11/its 的 dir 属性,两者都要能解析回来;tsv 解析要接受 "x"@ar--rtl;txt 输出 --rtl。
JSON-LD 的 @direction(与其他关键字一样可以设别名)映射到 Literal.direction:值对象只使用自身的方向;其他字符串值在其术语定义了方向时使用术语的方向(即使定义为 null),否则使用上下文的默认方向,与它们的语言标签从何而来无关。嵌入式上下文和作用域上下文继承默认方向,除非自己设置了方向;null 上下文会清除默认方向。没有语言标签的值,其方向被静默丢弃。"ltr"、"rtl" 和 null(无方向)以外的 @direction 值,在加载其所在的文档或 Context 时就要抛出 JSONLDException,消息中包含“invalid base direction”,即使这个值从未被用到。序列化器要给带方向字面量的值对象加上 @direction(或上下文为它定义的别名);对于带语言标签的字面量,只有当现在使用的裸字符串或语言映射形式读回时得到的方向(术语定义了 @direction 时取它,否则取上下文默认值)与字面量自身的方向相同(都没有方向也算相同),才保留这种形式;否则写成包含 @value、@language 以及(如有)@direction 的值对象。Context.direction 保存默认方向(未设置时为 None);它的术语增加 direction 字段,add_term() 增加 direction 参数(未给出时为 UNDEF);to_dict() 要为已设置的默认方向以及每个定义了方向的术语输出 @direction。
任何不带基础方向的内容,其行为和序列化结果都必须与现在完全一致。
重要:请从 main 新建一个分支进行开发,完成后提交所有改动。
隐藏测试检查什么
- Literal:第五个位置参数 direction、只读属性、ValueError/TypeError 校验、能区分三种变体的相等、哈希与 Graph 存储、repr、n3()、from_n3、pickle 与复制。
- RDF 语法:nt、nquads、turtle、trig、n3 在各自支持的每种字符串形式下都接受 @ar--rtl 及带子标签的写法,非法方向抛出 ParserError/BadSyntax;N-Triples/N-Quads 行的精确输出(含转义),以及 nt、nt11、nquads、turtle、longturtle、trig、n3 的往返。
- SPARQL:查询与更新中各处的带方向字面量(三元组模式、VALUES、BIND、CONSTRUCT、ASK、INSERT/DELETE DATA、DELETE/INSERT WHERE、命名图)与比较运算;LANGDIR、hasLANG、hasLANGDIR、STRLANGDIR(含出错时由 COALESCE 回退)、DATATYPE、LANG、字符串函数及 CONCAT 的标签/方向规则。
- 结果与存储:JSON its:dir 与 XML ITS dir 的往返、TSV 单元格与 TXT 输出;Memory 与 BerkeleyDB 存储重新打开后保留方向。
- JSON-LD 解析:方向取自值对象、术语定义还是上下文默认值;语言映射、列表、集合、索引映射与 @nest 中的值;嵌入式、属性作用域、类型作用域与 null 上下文;@direction 别名;数字、布尔与带类型的值不受影响,无语言标签时丢弃方向。
- JSON-LD 报错与 Context:值对象、上下文、术语定义、嵌入式与作用域上下文、上下文文件、传给解析器或序列化器的 context 参数以及 Context 对象中的非法 @direction,加载即抛 JSONLDException,未用到也一样;Context.direction、术语的 direction、add_term() 的 direction 参数与 to_dict() 的输出。
- JSON-LD 序列化:无上下文时写出带 @direction 的值对象;有上下文时裸字符串、语言映射条目与列表项只在读回方向一致时使用,别名同样生效,输出读回后与原图一致;不带方向的输出与现在相同。
- 端到端:Turtle→查询→JSON/XML 结果;N-Triples 数据经 STRLANGDIR 更新后再序列化;TriG→N-Quads 再转回;Turtle、TriG 与 SPARQL 更新得到的数据经 JSON-LD 写出再读回;引用上下文文件的 JSON-LD 文件经 SPARQL 查询语言标签与方向。
- 失败→通过测试
- 754
- 回归测试
- 9,319
- 构建/类型检查
- 2
- 参考解改动文件
- 19
- 参考解新增行
- +553
可定制
包括但不限于以下几项,其他需求都可以商量。
- 语言与代码库:编程语言和技术栈(也可扩展到 Java、C++ 等)、代码库类型和规模、改动规模。
- 任务配比与需求写法:新功能、功能增强、行为变更、修复、重构;需求的长短和语气,以及写明多少接口细节。
- 难度:对标的模型和要达到的通过率区间。
- 验证强度:隐藏测试数量、回归测试范围、构建/类型检查门禁。
- 轨迹:Agent 框架(DeepSWE 主榜同款 bash 框架、Claude Code 等)、模型和推理强度、每题的轨迹条数。
- 格式、数量和排期:Harbor / Pier 任务目录,ATIF 或请求级轨迹;交付数量和时间安排。