mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 11:53:16 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
|
|
@ -0,0 +1,112 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
@testable import OpenClaw
|
||||
|
||||
private struct SystemRunCommandContractFixture: Decodable {
|
||||
let cases: [SystemRunCommandContractCase]
|
||||
}
|
||||
|
||||
private struct SystemRunCommandContractCase: Decodable {
|
||||
let name: String
|
||||
let command: [String]
|
||||
let rawCommand: String?
|
||||
let expected: SystemRunCommandContractExpected
|
||||
}
|
||||
|
||||
private struct SystemRunCommandContractExpected: Decodable {
|
||||
let valid: Bool
|
||||
let displayCommand: String?
|
||||
let errorContains: String?
|
||||
}
|
||||
|
||||
struct ExecSystemRunCommandValidatorTests {
|
||||
@Test func `matches shared system run command contract fixture`() throws {
|
||||
for entry in try Self.loadContractCases() {
|
||||
let result = ExecSystemRunCommandValidator.resolve(command: entry.command, rawCommand: entry.rawCommand)
|
||||
|
||||
if !entry.expected.valid {
|
||||
switch result {
|
||||
case let .ok(resolved):
|
||||
Issue
|
||||
.record("\(entry.name): expected invalid result, got displayCommand=\(resolved.displayCommand)")
|
||||
case let .invalid(message):
|
||||
if let expected = entry.expected.errorContains {
|
||||
#expect(
|
||||
message.contains(expected),
|
||||
"\(entry.name): expected error containing \(expected), got \(message)")
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch result {
|
||||
case let .ok(resolved):
|
||||
#expect(
|
||||
resolved.displayCommand == entry.expected.displayCommand,
|
||||
"\(entry.name): unexpected display command")
|
||||
case let .invalid(message):
|
||||
Issue.record("\(entry.name): unexpected invalid result: \(message)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test func `validator keeps canonical wrapper text out of allowlist raw parsing`() {
|
||||
let command = ["/bin/sh", "-lc", "/usr/bin/printf ok"]
|
||||
let rawCommand = "/bin/sh -lc \"/usr/bin/printf ok\""
|
||||
let result = ExecSystemRunCommandValidator.resolve(command: command, rawCommand: rawCommand)
|
||||
|
||||
switch result {
|
||||
case let .ok(resolved):
|
||||
#expect(resolved.displayCommand == rawCommand)
|
||||
#expect(resolved.evaluationRawCommand == nil)
|
||||
case let .invalid(message):
|
||||
Issue.record("unexpected invalid result: \(message)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func `env dash shell wrapper requires canonical raw command binding`() {
|
||||
let command = ["/usr/bin/env", "-", "bash", "-lc", "echo hi"]
|
||||
|
||||
let legacy = ExecSystemRunCommandValidator.resolve(command: command, rawCommand: "echo hi")
|
||||
switch legacy {
|
||||
case .ok:
|
||||
Issue.record("expected rawCommand mismatch for env dash prelude")
|
||||
case let .invalid(message):
|
||||
#expect(message.contains("rawCommand does not match command"))
|
||||
}
|
||||
|
||||
let canonicalRaw = "/usr/bin/env - bash -lc \"echo hi\""
|
||||
let canonical = ExecSystemRunCommandValidator.resolve(command: command, rawCommand: canonicalRaw)
|
||||
switch canonical {
|
||||
case let .ok(resolved):
|
||||
#expect(resolved.displayCommand == canonicalRaw)
|
||||
case let .invalid(message):
|
||||
Issue.record("unexpected invalid result for canonical raw command: \(message)")
|
||||
}
|
||||
}
|
||||
|
||||
private static func loadContractCases() throws -> [SystemRunCommandContractCase] {
|
||||
let fixtureURL = try self.findContractFixtureURL()
|
||||
let data = try Data(contentsOf: fixtureURL)
|
||||
let decoded = try JSONDecoder().decode(SystemRunCommandContractFixture.self, from: data)
|
||||
return decoded.cases
|
||||
}
|
||||
|
||||
private static func findContractFixtureURL() throws -> URL {
|
||||
var cursor = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
|
||||
for _ in 0..<8 {
|
||||
let candidate = cursor
|
||||
.appendingPathComponent("test")
|
||||
.appendingPathComponent("fixtures")
|
||||
.appendingPathComponent("system-run-command-contract.json")
|
||||
if FileManager.default.fileExists(atPath: candidate.path) {
|
||||
return candidate
|
||||
}
|
||||
cursor.deleteLastPathComponent()
|
||||
}
|
||||
throw NSError(
|
||||
domain: "ExecSystemRunCommandValidatorTests",
|
||||
code: 1,
|
||||
userInfo: [NSLocalizedDescriptionKey: "missing shared system-run command contract fixture"])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue