Repository navigation
diag(shell): stage 5 的 transport oracle 内部状态 (#80) #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,4 +45,72 @@ inline void local_shell_size_readiness(const std::filesystem::path& directory, s | |
| <<",\"observed_output_tail_bytes\":"<<observed_bytes<<"}\n"; | ||
| progress.close(); require(bool(progress), "local shell size readiness write failed"); | ||
| } | ||
| // Diagnostic-only copy of the transport oracle's line rules. It never changes a | ||
| // pass or fail: the shells scenario calls it on its timeout path so a stage five | ||
| // failure can report which transport condition was unmet. | ||
| inline void local_shell_transport_probe(const std::filesystem::path& directory, std::string_view role, | ||
| std::string_view raw, std::string_view marker) { | ||
| bool output_seen = false, prompt_seen = false, literal = true, malformed = false; | ||
| std::string line; | ||
| const auto prompt = [](std::string_view text) { return text == "TF>" || text == "TF> "; }; | ||
| const auto end_line = [&] { | ||
| if (literal && line == marker) output_seen = true; | ||
| else if (literal && output_seen && prompt(line)) prompt_seen = true; | ||
| line.clear(); | ||
| literal = true; | ||
| }; | ||
| for (std::size_t i = 0; i < raw.size();) { | ||
| const auto byte = static_cast<unsigned char>(raw[i++]); | ||
| if (byte == 0x1b) { | ||
| if (i == raw.size()) { malformed = true; break; } | ||
| const char kind = raw[i++]; | ||
| if (kind == ']') { | ||
| bool terminated = false; | ||
| while (i < raw.size()) { | ||
| const char next = raw[i++]; | ||
| if (next == '\a') { terminated = true; break; } | ||
| if (next == '\x1b') { | ||
| if (i == raw.size() || raw[i++] != '\\') { malformed = true; break; } | ||
| terminated = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!terminated) { malformed = true; break; } | ||
| } else if (kind == '[') { | ||
| while (i < raw.size() && ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == ';' || raw[i] == '?')) ++i; | ||
| if (i == raw.size()) { malformed = true; break; } | ||
| ++i; | ||
| } else { malformed = true; break; } | ||
| } else if (byte == '\r') { | ||
| } else if (byte == '\n') { | ||
| end_line(); | ||
| } else if (byte == '\b') { | ||
| if (output_seen) { malformed = true; break; } | ||
| literal = false; | ||
| } else { | ||
| if (byte < 0x20 || byte == 0x7f) { malformed = true; break; } | ||
| line.push_back(static_cast<char>(byte)); | ||
| } | ||
| } | ||
| std::string escaped; | ||
| for (const char ch : line) { | ||
| if (escaped.size() > 160) { escaped += "..."; break; } | ||
| const auto byte = static_cast<unsigned char>(ch); | ||
| if (byte >= 0x20 && byte < 0x7f && ch != '"' && ch != '\\') escaped.push_back(ch); | ||
| else { | ||
| char buffer[8]{}; | ||
| std::snprintf(buffer, sizeof(buffer), "\\x%02x", byte); | ||
| escaped += buffer; | ||
|
Comment on lines
+102
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the unfinished output line contains a quote, backslash or non-ASCII byte, this emits Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
| std::ofstream progress(directory/"shells-transport-probe.jsonl", std::ios::binary | std::ios::app); | ||
| progress << "{\"schema\":\"termforge-local-shell-transport-probe-v1\",\"role\":\"" << role | ||
| << "\",\"marker\":\"" << marker | ||
| << "\",\"output_seen\":" << (output_seen ? "true" : "false") | ||
| << ",\"prompt_seen\":" << (prompt_seen ? "true" : "false") | ||
| << ",\"malformed\":" << (malformed ? "true" : "false") | ||
| << ",\"last_line\":\"" << escaped << "\"}\n"; | ||
| progress.close(); | ||
| } | ||
|
|
||
| } // namespace tf_shell_test | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The probe disagrees with
transport_output_completed()on the conditions it is intended to diagnose:TF_SIZE_80x24\r\nTF>completes the oracle but reportsprompt_seen=false, andTF_SIZE_80x24followed by a column-one CUP andTF>completes the oracle but reports both flags false. Conversely, the probe silently ignores bare CRs that the oracle rejects. Consequently, a timeout caused by another readiness condition can be incorrectly attributed to missing marker output or a missing prompt. Mirror the oracle's trailing-prompt, CUP-boundary, CSI-validation and CR rules, preferably through shared parsing logic so the diagnostic state cannot diverge.Useful? React with 👍 / 👎.