Skip to content

Commit 64d0aba

Browse files
committed
Keep raw availability details out of startup diagnostics
1 parent 0cbb3ee commit 64d0aba

5 files changed

Lines changed: 21 additions & 20 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ Call `OpenCliDiagnosticExport.export(result, 512)` explicitly with an `OpenCliRe
260260

261261
The SDK returns the text in memory. Your application controls the destination and retention. SDK diagnostics omit argv values, raw content, URLs and filesystem paths. Applications that use or log raw results should protect that data. `remoteCaptureRawHttpResponse` is still opt-in.
262262

263+
`OpenCliAvailabilityReport.toDiagnosticMessage()` is suitable for startup logs and reports readiness and status. Read the executable paths or probe message through their dedicated getters when needed.
264+
263265
At the low-level process boundary, `RunSession.getHandler().getException()` returns a safe I/O summary. `RunSession.getIoFailure()` is the explicit raw diagnostic accessor. Handle that exception as sensitive data because it can include local paths.
264266

265267
<a id="9-testing--build"></a>

‎README.zh-CN.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ collect 请求 ID 必须为非空白字符串,长度上限 128 个 UTF-8 字
260260

261261
SDK 在内存中返回文本,由应用决定目的地和保留时间。SDK 诊断会排除命令参数、原始内容、URL 和文件路径。应用读取或记录原始结果时应自行保护这些数据。`remoteCaptureRawHttpResponse` 仍需显式开启。
262262

263+
`OpenCliAvailabilityReport.toDiagnosticMessage()` 可用于启动日志,只输出就绪状态和状态码。需要查看可执行文件路径或原始探测消息时,调用对应的 getter。
264+
263265
低层进程接口的 `RunSession.getHandler().getException()` 返回安全的 I/O 摘要。`RunSession.getIoFailure()` 是显式读取原始诊断的入口,异常可能包含本地路径,应按敏感数据处理。
264266

265267
<a id="9-testing--build"></a>

‎openspec/changes/harden-opencli-diagnostics-privacy/tasks.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,12 @@ JDK 17 两项定向红灯实际退出 1。选项对象的 `toString()` 抛出带
4545
| HTTP 503、凭据 URL、畸形 JSON、原文捕获开关 | `OpenCliRemoteAgentHttpClientTest` |
4646
| WebSocket 断线和投递异常、配置 URL、日志测试密钥 | `OpenCliWsReverseAgentSessionTest`、`OpenCliWsReverseAgentClientTest` |
4747
| JSON 解析 DEBUG、默认不写入的有界导出 | `OpenCliStdoutJsonTest`、`OpenCliDiagnosticExportTest` |
48+
| 启动日志的可用性摘要,配置和探测原始值的显式读取 | `OpenCliAvailabilityReportTest` |
4849

4950
JDK 17 使用系统 Maven 执行 `-B -ntp -o clean verify`,2,134 项通过,0 失败、0 错误、0 跳过。中英文 README 记录应用显式访问原始低层诊断的责任。C03 的 YAML 解码器仍待实施,对其解析日志的验证保留在后续矩阵中。
51+
52+
## 启动诊断摘要验证
53+
54+
JDK 17 基线 `0cbb3ee750062675813f1d3389c5f7f14b50345c` 的定向用例在 3 项中失败 1 项。面向日志的 `toDiagnosticMessage()` 输出了配置值、解析后的可执行文件路径和原始探测消息。修改后,该方法只输出就绪状态和状态码。用例继续断言 `getConfiguredExecutable()`、`getResolvedExecutablePath()` 和 `getMessage()` 保留原始值。
55+
56+
三条线使用其 Maven Wrapper 运行 `./mvnw -B -ntp clean verify`,报告位于各自的 `target/surefire-reports`。Java 8 提交 `49250f97cb6618502b40e5989b8521fc733d7fab`、Java 17 本提交和 Java 21 提交 `7001ed85439408f9d2724e7edee92d3cfc7853e9` 分别通过 2178、2179、2178 项,均为零失败、零错误、零跳过。

‎src/main/java/io/github/easy4j/opencli/core/availability/OpenCliAvailabilityReport.java‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,11 @@ public boolean isAvailable() {
4040
}
4141

4242
/**
43-
* 构造面向日志/异常的诊断文本。
43+
* 构造可写入日志的就绪状态摘要。可执行文件和原始探测消息可通过各自的 getter 读取。
4444
*
4545
* @return 说明字符串
4646
*/
4747
public String toDiagnosticMessage() {
48-
StringBuilder sb = new StringBuilder();
49-
sb.append("OpenCLI ");
50-
sb.append(available ? "ready" : "unavailable");
51-
sb.append(" [").append(status).append(']');
52-
if (configuredExecutable != null) {
53-
sb.append(" executable=").append(configuredExecutable);
54-
}
55-
if (resolvedExecutablePath != null) {
56-
sb.append(" resolved=").append(resolvedExecutablePath);
57-
}
58-
if (message != null && !message.isEmpty()) {
59-
sb.append(" — ").append(message);
60-
}
61-
return sb.toString();
48+
return "OpenCLI " + (available ? "ready" : "unavailable") + " [" + status + "]";
6249
}
6350
}

‎src/test/java/io/github/easy4j/opencli/core/availability/OpenCliAvailabilityReportTest.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ void shouldBuildReport() {
2323
}
2424

2525
@Test
26-
void shouldGenerateDiagnosticMessage() {
26+
void shouldKeepPathsAndProviderDetailsOutOfDiagnosticMessage() {
2727
OpenCliAvailabilityReport report = OpenCliAvailabilityReport.builder()
2828
.status(OpenCliAvailabilityStatus.EXECUTABLE_NOT_FOUND)
2929
.available(false)
30-
.configuredExecutable("opencli")
31-
.message("not found on PATH")
30+
.configuredExecutable("private-configured-executable")
31+
.resolvedExecutablePath("/private/resolved-executable")
32+
.message("private-probe-detail")
3233
.build();
3334
String diag = report.toDiagnosticMessage();
3435
assertTrue(diag.contains("unavailable"));
3536
assertTrue(diag.contains("EXECUTABLE_NOT_FOUND"));
36-
assertTrue(diag.contains("opencli"));
37-
assertTrue(diag.contains("not found on PATH"));
37+
assertFalse(diag.contains("private"));
38+
assertEquals("private-configured-executable", report.getConfiguredExecutable());
39+
assertEquals("/private/resolved-executable", report.getResolvedExecutablePath());
40+
assertEquals("private-probe-detail", report.getMessage());
3841
}
3942

4043
@Test

0 commit comments

Comments
 (0)