Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions experiments/shell/local_shell_diagnostics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Comment on lines +79 to +84

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match the actual oracle when reporting transport state

The probe disagrees with transport_output_completed() on the conditions it is intended to diagnose: TF_SIZE_80x24\r\nTF> completes the oracle but reports prompt_seen=false, and TF_SIZE_80x24 followed by a column-one CUP and TF> 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 👍 / 👎.

} 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Encode last_line using valid JSON escapes

If the unfinished output line contains a quote, backslash or non-ASCII byte, this emits \x22, \x5c or similar sequences directly into the JSON string. JSON does not support \xNN escapes, so ordinary command text or Windows paths make the new .jsonl record unparsable; a local probe with TF>echo "C:\tmp" reproduces the failure with json.loads. Use valid JSON escaping, or JSON-escape the diagnostic hex representation before writing it.

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
8 changes: 5 additions & 3 deletions experiments/shell/workspace_shells_scenario.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ inline void Workspace::scenario_shells() {
const std::string role(tab.launch->kind.begin(), tab.launch->kind.end());
// WSL also has to show a fresh prompt after its marker; record that
// condition explicitly instead of leaving it to inference.
const std::string size_marker = "TF_SIZE_" + std::to_string(columns) + "x" + std::to_string(rows);
const bool transport_completed = tab.launch->kind != L"wsl" ||
tf_shell_test::transport_output_completed(
tab.shell->observed_output(),
"TF_SIZE_" + std::to_string(columns) + "x" + std::to_string(rows));
tf_shell_test::transport_output_completed(tab.shell->observed_output(), size_marker);
if (tab.launch->kind == L"wsl")
tf_shell_test::local_shell_transport_probe(diagnostic_directory, role,
tab.shell->observed_output(), size_marker);
tf_shell_test::local_shell_size_readiness(
diagnostic_directory, role, static_cast<unsigned long>(columns), static_cast<unsigned long>(rows),
tab.shell->settled(),
Expand Down
Loading