Phase 28: add project diagnostics, dependency inspection and durability regressions

This commit is contained in:
Johannes Findeisen 2026-10-27 16:58:26 +01:00
commit ca6c869b0b
16 changed files with 495 additions and 42 deletions

View file

@ -961,8 +961,14 @@ xtc_result MainWindow::open_project(const char *path)
std::string loaded_path(path);
xtc_project *candidate = nullptr;
xtc_result r = xtc_project_create(&candidate);
if (r == XTC_OK)
r = xtc_project_load(candidate, path);
xtc_project_diagnostic diagnostic{};
if (r == XTC_OK) {
r = xtc_project_load_diagnostic(candidate,path,&diagnostic);
if (r != XTC_OK) {
project_issue_ = "Project load line " + std::to_string(diagnostic.line) + " (" + diagnostic.record + "): " + diagnostic.message;
report_error(project_issue_.c_str(),r);
}
}
if (r == XTC_OK)
r = install_project(candidate);
if (r != XTC_OK) {

View file

@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include "xtc/xtc.h"
#include "xtc/xtc_version.h"
@ -8,11 +9,67 @@
#include "xtc/xtc_audio.h"
#include "xtc/xtc_midi.h"
#include <limits.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <unistd.h>
#include "xtc/xtc_plugin.h"
/* Dependency inspection checks readable regular files, never plugin code or
* audio contents. Escape untrusted path/label bytes in terminal output. */
static void quoted(const char *text)
{
const unsigned char *p = (const unsigned char *)text;
putchar('"');
for (; *p; ++p) {
if (*p == '"' || *p == '\\') printf("\\%c",*p);
else if (*p < 32 || *p == 127) printf("\\x%02x",(unsigned int)*p);
else putchar(*p);
}
putchar('"');
}
static int readable_file(const char *path)
{
struct stat info;
return stat(path,&info) == 0 && S_ISREG(info.st_mode) && access(path,R_OK) == 0;
}
static int inspect(const xtc_project *project, uint64_t version)
{
size_t tracks = 0, clips = 0, nodes = 0, edges = 0, i, missing = 0;
const xtc_graph *graph = xtc_project_graph(project);
xtc_project_get_counts(project,&tracks,&clips);
xtc_graph_get_counts(graph,&nodes,&edges);
printf("Project format %" PRIu64 " (writer %u): %zu tracks/buses, %zu clips, %zu graph nodes, %zu edges.\n",
version,XTC_PROJECT_FORMAT_VERSION,tracks,clips,nodes,edges);
for (i = 0; i < clips; ++i) {
xtc_clip_info clip;
xtc_project_get_clip(project,i,&clip);
if (clip.asset_path[0]) {
int available = readable_file(clip.asset_path);
printf("Media clip %" PRIu64 ": %s ",clip.id,available ? "available" : "missing/unreadable");
quoted(clip.asset_path); putchar('\n');
if (!available) ++missing;
}
}
for (i = 0; i < nodes; ++i) {
xtc_node_info node; xtc_plugin_spec spec;
xtc_graph_get_node(graph,i,&node);
if (xtc_graph_get_plugin(graph,node.id,&spec) == XTC_OK) {
int available = readable_file(spec.path);
printf("LADSPA node %zu ID %u descriptor %u ",node.id,spec.unique_id,spec.index);
quoted(spec.label); printf(": %s ",available ? "available" : "missing/unreadable");
quoted(spec.path); putchar('\n');
if (!available) ++missing;
}
}
printf("Dependency references missing/unreadable: %zu.\n",missing);
puts("File availability only: WAV contents, plugin identity/initialization, JACK and hardware not checked; no plugin code executed.");
return missing ? 2 : EXIT_SUCCESS;
}
/**
* @brief Runs the xtc-check command-line entry point.
*
* Supports --version, --help, and --validate PROJECT. With no arguments it
* Supports version/help, metadata validation and dependency inspection. With no arguments it
* creates and destroys the application shell to check core startup/shutdown.
* Any other argument count prints usage to stderr.
*
@ -38,7 +95,7 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
if (argc == 2 && !strcmp(argv[1], "--help")) {
puts("Usage: xtc-check [--version | --help | --diagnose | --validate PROJECT | --recover-recording TEMP NEW.wav]\nNo arguments checks core startup/shutdown. "
puts("Usage: xtc-check [--version | --help | --diagnose | --validate PROJECT | --inspect PROJECT | --recover-recording TEMP NEW.wav]\nNo arguments checks core startup/shutdown. "
"Validation checks metadata only.");
return EXIT_SUCCESS;
}
@ -52,21 +109,28 @@ int main(int argc, char **argv)
puts("Complete recorded frames recovered; source retained.");
return EXIT_SUCCESS;
}
if (argc == 3 && !strcmp(argv[1], "--validate")) {
if (argc == 3 && (!strcmp(argv[1], "--validate") || !strcmp(argv[1], "--inspect"))) {
xtc_project *project = NULL;
xtc_project_diagnostic diagnostic = {0};
xtc_result result = xtc_project_create(&project);
if (result == XTC_OK)
result = xtc_project_load(project, argv[2]);
xtc_project_destroy(project);
if (result == XTC_OK) result = xtc_project_load_diagnostic(project,argv[2],&diagnostic);
if (result != XTC_OK) {
fprintf(stderr, "Project validation failed: %s\n", xtc_result_string(result));
fprintf(stderr,"Project validation failed: %s; line %zu, %s: %s\n",xtc_result_string(result),
diagnostic.line,diagnostic.record,diagnostic.message);
xtc_project_destroy(project);
return EXIT_FAILURE;
}
if (!strcmp(argv[1],"--inspect")) {
int code = inspect(project,diagnostic.format_version);
xtc_project_destroy(project);
return code;
}
xtc_project_destroy(project);
puts("Project metadata valid (external assets not loaded).");
return EXIT_SUCCESS;
}
if (argc != 1) {
fputs("Usage: xtc-check [--version | --help | --diagnose | --validate PROJECT | --recover-recording TEMP NEW.wav]\n", stderr);
fputs("Usage: xtc-check [--version | --help | --diagnose | --validate PROJECT | --inspect PROJECT | --recover-recording TEMP NEW.wav]\n", stderr);
return EXIT_FAILURE;
}

View file

@ -12,10 +12,13 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
typedef struct {
FILE *file;
size_t bytes;
size_t bytes, line_number, record_line;
uint64_t version;
char expected[32];
char line[1536];
char *tokens[12];
size_t count;
@ -33,6 +36,7 @@ static xtc_result line(reader *input)
int byte;
char *cursor;
input->count = 0U;
input->record_line = ++input->line_number;
while ((byte = fgetc(input->file)) != EOF) {
if (++input->bytes > 4194304U)
return XTC_ERR_FORMAT;
@ -166,7 +170,9 @@ static int decode_float(const char *text, float *value)
#define READ(tag, total) \
do { \
xtc_result read_result = line(input); \
xtc_result read_result; \
snprintf(input->expected, sizeof(input->expected), "%s", (tag)); \
read_result = line(input); \
if (read_result != XTC_OK) \
return read_result; \
if (input->count != (total) || strcmp(input->tokens[0], (tag)) != 0) \
@ -193,6 +199,7 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
xtc_graph *graph = project->graph;
READ("XTC_PROJECT", 2U);
NUM(1U, version);
input->version = version;
if (version < 1U || version > XTC_PROJECT_FORMAT_VERSION)
return XTC_ERR_UNSUPPORTED;
format_version = version;
@ -435,6 +442,8 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
return XTC_ERR_FORMAT;
if (ferror(input->file))
return XTC_ERR_IO;
input->record_line = 0;
snprintf(input->expected,sizeof(input->expected),"%s","ASSET_PATH");
if (format_version >= 7) for (i = 0; i < project->clip_count; ++i) {
char *asset = project->clips[i].asset_path;
if (asset[0] && asset[0] != '/') {
@ -444,6 +453,7 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
memcpy(asset,directory,root); asset[root] = '/';
}
}
snprintf(input->expected,sizeof(input->expected),"%s","MODEL");
return xtc_project_validate(project);
}
@ -612,36 +622,64 @@ static char *project_folder(const char *path)
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_load(xtc_project *project, const char *path)
static xtc_result load_report(const reader *input, xtc_result result, xtc_project_diagnostic *out)
{
xtc_project_diagnostic d = {0};
d.result = result;
d.format_version = input->version;
d.line = result == XTC_OK ? 0 : input->record_line;
if (result != XTC_OK) snprintf(d.record,sizeof(d.record),"%s",input->expected);
if (result == XTC_OK) snprintf(d.message,sizeof(d.message),"Metadata valid; external media/plugins not loaded.");
else if (result == XTC_ERR_UNSUPPORTED && !strcmp(input->expected,"XTC_PROJECT"))
snprintf(d.message,sizeof(d.message),"Project format %" PRIu64 " is unsupported; this build reads versions 1..%u.",input->version,XTC_PROJECT_FORMAT_VERSION);
else if (result == XTC_ERR_UNSUPPORTED) snprintf(d.message,sizeof(d.message),"Unsupported project feature or node type; no data was discarded.");
else if (result == XTC_ERR_FORMAT && !strcmp(input->expected,"SIZE")) snprintf(d.message,sizeof(d.message),"Project exceeds the 4 MiB input limit.");
else if (result == XTC_ERR_FORMAT && !strcmp(input->expected,"MODEL")) snprintf(d.message,sizeof(d.message),"Invalid project references, IDs, graph, routing or values.");
else if (result == XTC_ERR_FORMAT) snprintf(d.message,sizeof(d.message),"Invalid, unknown or truncated record; expected %s. Unknown fields are rejected.",input->expected);
else if (result == XTC_ERR_IO) snprintf(d.message,sizeof(d.message),"Cannot read project or resolve its containing directory; check path and permissions.");
else if (result == XTC_ERR_CAPACITY) snprintf(d.message,sizeof(d.message),"Project capacity or resolved media path exceeds supported limits.");
else snprintf(d.message,sizeof(d.message),"Project load failed: %s.",xtc_result_string(result));
if (out) *out = d;
return result;
}
xtc_result xtc_project_load_diagnostic(xtc_project *project, const char *path, xtc_project_diagnostic *diagnostic)
{
xtc_project *candidate = NULL;
reader input = {0};
char *directory;
xtc_result result;
struct stat info;
snprintf(input.expected,sizeof(input.expected),"%s","OPEN");
if (project == NULL || path_length(path) == 0U)
return XTC_ERR_INVALID_ARGUMENT;
return load_report(&input,XTC_ERR_INVALID_ARGUMENT,diagnostic);
input.file = fopen(path, "rb");
if (input.file == NULL)
return XTC_ERR_IO;
if (input.file == NULL) return load_report(&input,XTC_ERR_IO,diagnostic);
if (fstat(fileno(input.file),&info) == 0 && S_ISREG(info.st_mode) && info.st_size > 4194304) {
snprintf(input.expected,sizeof(input.expected),"%s","SIZE");
fclose(input.file);
return load_report(&input,XTC_ERR_FORMAT,diagnostic);
}
{
char *canonical = realpath(path,NULL);
directory = canonical ? project_folder(canonical) : NULL;
free(canonical);
}
if (!directory) { fclose(input.file); return XTC_ERR_IO; }
if (!directory) { fclose(input.file); return load_report(&input,XTC_ERR_IO,diagnostic); }
result = xtc_project_create(&candidate);
if (result == XTC_OK)
result = read_project(&input, candidate, directory);
if (result == XTC_OK) result = read_project(&input, candidate, directory);
free(directory);
if (fclose(input.file) != 0 && result == XTC_OK)
result = XTC_ERR_IO;
if (fclose(input.file) != 0 && result == XTC_OK) result = XTC_ERR_IO;
if (result == XTC_OK) {
xtc_graph *old = project->graph;
*project = *candidate;
candidate->graph = old;
}
xtc_project_destroy(candidate);
return result;
return load_report(&input,result,diagnostic);
}
xtc_result xtc_project_load(xtc_project *project, const char *path)
{
return xtc_project_load_diagnostic(project,path,NULL);
}
/**