Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

feat(foundation): classify indexing roots by breadth and sensitivity

Martin Vogel03e935576b7d
diff --git a/Makefile.cbm b/Makefile.cbm
index 1dbe4d7d1..2b0a947a2 100644
--- a/Makefile.cbm
+++ b/Makefile.cbm
@@ -188,6 +188,7 @@ FOUNDATION_SRCS = \
src/foundation/str_intern.c \
src/foundation/log.c \
src/foundation/str_util.c \
+ src/foundation/workspace.c \
src/foundation/platform.c \
src/foundation/system_info.c \
src/foundation/slab_alloc.c \
@@ -453,6 +454,7 @@ TEST_FOUNDATION_SRCS = \
tests/test_str_intern.c \
tests/test_log.c \
tests/test_str_util.c \
+ tests/test_workspace.c \
tests/test_platform.c \
tests/test_diagnostics.c \
tests/test_dump_verify.c \
diff --git a/src/foundation/workspace.c b/src/foundation/workspace.c
new file mode 100644
index 000000000..0519c09e7
--- /dev/null
+++ b/src/foundation/workspace.c
@@ -0,0 +1,265 @@
+/*
+ * workspace.c — workspace boundary policy. See workspace.h for the contract and
+ * for why this is only the breadth half of the boundary.
+ */
+#include "foundation/workspace.h"
+
+#include <string.h>
+
+enum {
+ /* POSIX: two components, so every top-level tree is refused in one rule with
+ * no list to maintain — "/etc", "/home", "/Users", "/var", "/opt", "/srv".
+ * Depth alone cannot do this on Windows, where the equivalent system trees
+ * and a perfectly ordinary workspace are both one component below the drive
+ * ("C:/Windows" and "D:/repos"), so Windows uses one component plus the
+ * named system directories below. Windows' top-level set is small and stable
+ * enough for a list; POSIX's is not. */
+ WS_MIN_DEPTH_POSIX = 2,
+ WS_MIN_DEPTH_WINDOWS = 1,
+};
+
+static bool ws_is_sep(char c) {
+ return c == '/' || c == '\\';
+}
+
+/* Length of the volume prefix: "/" on POSIX, "C:/" for a drive, "//srv/share"
+ * for a UNC share. Returns 0 when the path is not absolute. */
+static size_t ws_volume_prefix_len(const char *path) {
+ if (!path || !path[0]) {
+ return 0;
+ }
+ /* UNC: two separators, a host, then a share. */
+ if (ws_is_sep(path[0]) && ws_is_sep(path[1])) {
+ size_t i = 2;
+ while (path[i] && !ws_is_sep(path[i])) { /* host */
+ i++;
+ }
+ while (ws_is_sep(path[i])) {
+ i++;
+ }
+ while (path[i] && !ws_is_sep(path[i])) { /* share */
+ i++;
+ }
+ return i;
+ }
+ if (ws_is_sep(path[0])) {
+ return 1;
+ }
+ /* Drive-letter root, with or without a trailing separator. */
+ if (path[1] == ':' &&
+ ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z'))) {
+ return ws_is_sep(path[2]) ? 3 : 2;
+ }
+ return 0;
+}
+
+static bool ws_is_unc(const char *path) {
+ return path && ws_is_sep(path[0]) && ws_is_sep(path[1]);
+}
+
+static bool ws_is_windows_style(const char *path) {
+ if (!path || !path[0]) {
+ return false;
+ }
+ return path[1] == ':' &&
+ ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z'));
+}
+
+int cbm_workspace_path_depth(const char *canonical_path) {
+ size_t prefix = ws_volume_prefix_len(canonical_path);
+ if (prefix == 0) {
+ return 0;
+ }
+ int depth = 0;
+ const char *p = canonical_path + prefix;
+ while (*p) {
+ while (ws_is_sep(*p)) {
+ p++;
+ }
+ if (!*p) {
+ break;
+ }
+ depth++;
+ while (*p && !ws_is_sep(*p)) {
+ p++;
+ }
+ }
+ return depth;
+}
+
+/* Case-insensitive on Windows-style paths, exact elsewhere: NTFS is
+ * case-insensitive, so ".SSH" must not slip past a case-sensitive compare. */
+static bool ws_component_equals(const char *component, size_t len, const char *name,
+ bool fold_case) {
+ if (strlen(name) != len) {
+ return false;
+ }
+ for (size_t i = 0; i < len; i++) {
+ char a = component[i];
+ char b = name[i];
+ if (fold_case) {
+ if (a >= 'A' && a <= 'Z') {
+ a = (char)(a - 'A' + 'a');
+ }
+ if (b >= 'A' && b <= 'Z') {
+ b = (char)(b - 'A' + 'a');
+ }
+ }
+ if (a != b) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/* Directory and file names that carry credentials. Matched against every
+ * component, so both "…/.ssh" and "…/.ssh/sub" are refused. Additive by design:
+ * a pull request appending a name here needs no design authority. */
+static const char *const WS_CREDENTIAL_NAMES[] = {
+ ".ssh",
+ ".aws",
+ ".gnupg",
+ ".gpg",
+ ".kube",
+ ".docker",
+ ".netrc",
+ "_netrc",
+ ".git-credentials",
+ ".azure",
+ ".gcloud",
+ "Keychains",
+ ".password-store",
+ ".authinfo",
+};
+
+/* Windows top-level trees below the drive. Small and stable enough to list,
+ * which is what lets Windows use a shallower depth minimum. */
+static const char *const WS_WINDOWS_SYSTEM_DIRS[] = {
+ "Windows", "Users", "ProgramData", "Program Files", "Program Files (x86)",
+};
+
+static bool ws_any_component_matches(const char *path, const char *const *names, size_t count,
+ bool fold_case) {
+ size_t prefix = ws_volume_prefix_len(path);
+ const char *p = path + prefix;
+ while (*p) {
+ while (ws_is_sep(*p)) {
+ p++;
+ }
+ if (!*p) {
+ break;
+ }
+ const char *start = p;
+ while (*p && !ws_is_sep(*p)) {
+ p++;
+ }
+ size_t len = (size_t)(p - start);
+ for (size_t i = 0; i < count; i++) {
+ if (ws_component_equals(start, len, names[i], fold_case)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+/* True when b is a or lives under a. Compares on a separator boundary so
+ * "/a/bc" is not treated as living under "/a/b". */
+static bool ws_is_ancestor_or_equal(const char *a, const char *b) {
+ if (!a || !b || !a[0] || !b[0]) {
+ return false;
+ }
+ size_t la = strlen(a);
+ while (la > 1 && ws_is_sep(a[la - 1])) {
+ la--;
+ }
+ if (strncmp(a, b, la) != 0) {
+ return false;
+ }
+ return b[la] == '\0' || ws_is_sep(b[la]);
+}
+
+static bool ws_paths_equal(const char *a, const char *b) {
+ return ws_is_ancestor_or_equal(a, b) && ws_is_ancestor_or_equal(b, a);
+}
+
+cbm_ws_verdict_t cbm_workspace_classify_root(const char *canonical_path, const char *home_dir,
+ const char *cache_dir) {
+ if (!canonical_path || !canonical_path[0] || ws_volume_prefix_len(canonical_path) == 0) {
+ /* A relative or empty path is not a usable root; refuse it the same way
+ * as a volume root rather than letting it fall through as allowed. */
+ return CBM_WS_DENY_ABSOLUTE;
+ }
+
+ bool windows_style = ws_is_windows_style(canonical_path);
+ int depth = cbm_workspace_path_depth(canonical_path);
+
+ /* A volume, drive or share root, whatever the platform. */
+ if (depth == 0) {
+ return CBM_WS_DENY_ABSOLUTE;
+ }
+
+ /* Order matters below, and not for cosmetic reasons.
+ *
+ * The home directory normally CONTAINS the cache directory, so testing the
+ * cache first would report every $HOME as "holds the cache" — and, worse,
+ * would make it absolutely denied when the design says a person may override
+ * it. Home is therefore classified first.
+ *
+ * Depth comes before the cache test for the same kind of reason: "/Users" is
+ * both too broad and an ancestor of the cache, and "too broad, name a
+ * project directory below it" is the reason that actually helps the reader. */
+ if (home_dir && home_dir[0] && ws_paths_equal(canonical_path, home_dir)) {
+ return CBM_WS_DENY_SENSITIVE;
+ }
+
+ /* Below a drive or a UNC share the first component is already user space
+ * ("D:/repos", "//srv/share/proj"), so one component is enough there. Below a
+ * POSIX root it is a system tree, so require two. */
+ int min_depth =
+ (windows_style || ws_is_unc(canonical_path)) ? WS_MIN_DEPTH_WINDOWS : WS_MIN_DEPTH_POSIX;
+ if (depth < min_depth) {
+ return CBM_WS_DENY_TOO_SHALLOW;
+ }
+
+ /* Indexing a tree that holds the cache would pull every other project's
+ * graph database into this project's index. Never overridable. */
+ if (cache_dir && cache_dir[0] && ws_is_ancestor_or_equal(canonical_path, cache_dir)) {
+ return CBM_WS_DENY_ABSOLUTE;
+ }
+
+ if (ws_any_component_matches(canonical_path, WS_CREDENTIAL_NAMES,
+ sizeof(WS_CREDENTIAL_NAMES) / sizeof(WS_CREDENTIAL_NAMES[0]),
+ windows_style)) {
+ return CBM_WS_DENY_SENSITIVE;
+ }
+
+ if (windows_style &&
+ ws_any_component_matches(canonical_path, WS_WINDOWS_SYSTEM_DIRS,
+ sizeof(WS_WINDOWS_SYSTEM_DIRS) / sizeof(WS_WINDOWS_SYSTEM_DIRS[0]),
+ true)) {
+ return CBM_WS_DENY_SENSITIVE;
+ }
+
+ return CBM_WS_ALLOW;
+}
+
+const char *cbm_workspace_verdict_reason(cbm_ws_verdict_t verdict) {
+ switch (verdict) {
+ case CBM_WS_ALLOW:
+ return "allowed";
+ case CBM_WS_DENY_TOO_SHALLOW:
+ return "path is too broad to index as one root; name a project directory below it";
+ case CBM_WS_DENY_ABSOLUTE:
+ return "path is a volume root or holds the codebase-memory cache; it cannot be indexed";
+ case CBM_WS_DENY_SENSITIVE:
+ return "path is a home or credential directory";
+ default:
+ break;
+ }
+ return "refused";
+}
+
+bool cbm_workspace_verdict_is_overridable(cbm_ws_verdict_t verdict) {
+ return verdict == CBM_WS_DENY_SENSITIVE;
+}
diff --git a/src/foundation/workspace.h b/src/foundation/workspace.h
new file mode 100644
index 000000000..0d0511a95
--- /dev/null
+++ b/src/foundation/workspace.h
@@ -0,0 +1,54 @@
+#ifndef CBM_FOUNDATION_WORKSPACE_H
+#define CBM_FOUNDATION_WORKSPACE_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+/*
+ * Workspace boundary policy — classify a directory as an indexing root.
+ *
+ * This is the breadth half of the boundary: it rejects roots that are too broad
+ * or too sensitive to be indexed as a unit. It is NOT the authorization half.
+ * Whether a caller may index a given tree at all is answered by the user-level
+ * grant store, because that is the only input a caller cannot write. A verdict
+ * of CBM_WS_ALLOW here means "this path is not obviously too broad", never
+ * "this path is authorized".
+ *
+ * Every function takes an ALREADY-CANONICALIZED absolute path. Classifying
+ * before symlink resolution lets `/a/b/c/d/e/link -> /` present as a deep path
+ * and launder straight through, so callers must resolve first.
+ *
+ * home_dir and cache_dir are passed in rather than read from the environment so
+ * the policy is a pure function and can be tested without touching the host.
+ * Either may be NULL, which disables the checks that depend on it.
+ */
+
+typedef enum {
+ CBM_WS_ALLOW = 0,
+ /* Fewer path components than the platform minimum — e.g. "/etc", "/home". */
+ CBM_WS_DENY_TOO_SHALLOW,
+ /* A filesystem root, a drive root, a UNC share root, or a path that is or
+ * contains the cbm cache directory. Never overridable. */
+ CBM_WS_DENY_ABSOLUTE,
+ /* The home directory itself, or a credential/system directory. Overridable
+ * by an explicit human action, never by a manifest or a tool call. */
+ CBM_WS_DENY_SENSITIVE,
+} cbm_ws_verdict_t;
+
+/* Classify canonical_path as a candidate indexing root. */
+cbm_ws_verdict_t cbm_workspace_classify_root(const char *canonical_path, const char *home_dir,
+ const char *cache_dir);
+
+/* Stable, human-facing reason for a verdict. Never NULL. */
+const char *cbm_workspace_verdict_reason(cbm_ws_verdict_t verdict);
+
+/* True when an explicit human action may override this verdict. Absolute denials
+ * and shallow paths are never overridable; sensitive ones are. */
+bool cbm_workspace_verdict_is_overridable(cbm_ws_verdict_t verdict);
+
+/* Number of path components below the volume root, ignoring repeated and
+ * trailing separators. "/" is 0, "/etc" is 1, "C:/repos" is 1, "//srv/share" is
+ * 0 (the share root itself). Exposed for tests. */
+int cbm_workspace_path_depth(const char *canonical_path);
+
+#endif /* CBM_FOUNDATION_WORKSPACE_H */
diff --git a/tests/test_main.c b/tests/test_main.c
index 6fec09ea9..a46ec8338 100644
--- a/tests/test_main.c
+++ b/tests/test_main.c
@@ -603,6 +603,7 @@ extern void suite_dyn_array(void);
extern void suite_str_intern(void);
extern void suite_log(void);
extern void suite_str_util(void);
+extern void suite_workspace(void);
extern void suite_platform(void);
extern void suite_diagnostics(void);
extern void suite_subprocess(void);
@@ -848,6 +849,7 @@ int main(int argc, char **argv) {
RUN_SELECTED_SUITE(str_intern);
RUN_SELECTED_SUITE(log);
RUN_SELECTED_SUITE(str_util);
+ RUN_SELECTED_SUITE(workspace);
RUN_SELECTED_SUITE(platform);
RUN_SELECTED_SUITE(diagnostics);
RUN_SELECTED_SUITE(subprocess);
diff --git a/tests/test_workspace.c b/tests/test_workspace.c
new file mode 100644
index 000000000..60c6dcaa3
--- /dev/null
+++ b/tests/test_workspace.c
@@ -0,0 +1,162 @@
+/*
+ * test_workspace.c — workspace boundary policy.
+ *
+ * The policy is a pure function over an already-canonicalized path, so these are
+ * table tests with no filesystem involved. home_dir and cache_dir are injected.
+ */
+#include "../src/foundation/compat.h"
+#include "test_framework.h"
+#include "foundation/workspace.h"
+
+static const char *HOME = "/Users/dev";
+static const char *CACHE = "/Users/dev/.cache/codebase-memory-mcp";
+
+TEST(ws_depth_counts_components_below_the_volume) {
+ ASSERT_EQ(cbm_workspace_path_depth("/"), 0);
+ ASSERT_EQ(cbm_workspace_path_depth("/etc"), 1);
+ ASSERT_EQ(cbm_workspace_path_depth("/etc/"), 1);
+ ASSERT_EQ(cbm_workspace_path_depth("/Users/dev"), 2);
+ ASSERT_EQ(cbm_workspace_path_depth("/Users//dev///x"), 3);
+ /* Drive-relative, so an ordinary Windows workspace is one deep. */
+ ASSERT_EQ(cbm_workspace_path_depth("C:/"), 0);
+ ASSERT_EQ(cbm_workspace_path_depth("D:/repos"), 1);
+ ASSERT_EQ(cbm_workspace_path_depth("D:\\repos\\app"), 2);
+ /* A UNC share root is the share itself. */
+ ASSERT_EQ(cbm_workspace_path_depth("//srv/share"), 0);
+ ASSERT_EQ(cbm_workspace_path_depth("//srv/share/proj"), 1);
+ PASS();
+}
+
+TEST(ws_volume_roots_are_absolutely_denied) {
+ ASSERT_EQ(cbm_workspace_classify_root("/", HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ ASSERT_EQ(cbm_workspace_classify_root("C:/", HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ ASSERT_EQ(cbm_workspace_classify_root("C:\\", HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ ASSERT_EQ(cbm_workspace_classify_root("//srv/share", HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ ASSERT_FALSE(cbm_workspace_verdict_is_overridable(CBM_WS_DENY_ABSOLUTE));
+ PASS();
+}
+
+/* A relative or empty path is not a usable root and must not fall through as
+ * allowed just because no rule matched it. */
+TEST(ws_non_absolute_paths_are_denied) {
+ ASSERT_EQ(cbm_workspace_classify_root("", HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ ASSERT_EQ(cbm_workspace_classify_root("relative/path", HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ ASSERT_EQ(cbm_workspace_classify_root(NULL, HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ PASS();
+}
+
+/* One depth rule refuses every POSIX top-level tree without a list to maintain.
+ * This is the whole reason depth carries its weight. */
+TEST(ws_posix_top_level_trees_are_too_shallow) {
+ static const char *const shallow[] = {"/etc", "/home", "/Users", "/var",
+ "/opt", "/srv", "/usr", "/private"};
+ for (size_t i = 0; i < sizeof(shallow) / sizeof(shallow[0]); i++) {
+ ASSERT_EQ(cbm_workspace_classify_root(shallow[i], HOME, CACHE), CBM_WS_DENY_TOO_SHALLOW);
+ }
+ ASSERT_FALSE(cbm_workspace_verdict_is_overridable(CBM_WS_DENY_TOO_SHALLOW));
+ PASS();
+}
+
+/* Legitimately shallow project roots must survive: these are the false positives
+ * a blanket depth rule would cause, which is why Windows counts drive-relative. */
+TEST(ws_legitimate_shallow_roots_are_allowed) {
+ ASSERT_EQ(cbm_workspace_classify_root("/opt/sdk", HOME, CACHE), CBM_WS_ALLOW);
+ ASSERT_EQ(cbm_workspace_classify_root("/srv/protos", HOME, CACHE), CBM_WS_ALLOW);
+ ASSERT_EQ(cbm_workspace_classify_root("D:/repos", HOME, CACHE), CBM_WS_ALLOW);
+ ASSERT_EQ(cbm_workspace_classify_root("//srv/share/proj", HOME, CACHE), CBM_WS_ALLOW);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/dev/app", HOME, CACHE), CBM_WS_ALLOW);
+ PASS();
+}
+
+/* $HOME is depth 2 on both macOS and Linux, so depth cannot see it. */
+TEST(ws_home_itself_is_sensitive_but_subdirs_are_fine) {
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/projects", HOME, CACHE), CBM_WS_ALLOW);
+ /* A sibling that merely shares a prefix is not the home directory. */
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/developer", HOME, CACHE), CBM_WS_ALLOW);
+ ASSERT_TRUE(cbm_workspace_verdict_is_overridable(CBM_WS_DENY_SENSITIVE));
+ PASS();
+}
+
+/* The enumeration bypass: a credential directory passes every breadth rule, so
+ * it has to be named. Matched on any component, so subdirectories go too. */
+TEST(ws_credential_directories_are_sensitive_at_any_depth) {
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.ssh", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.ssh/keys", HOME, CACHE),
+ CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.aws", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.gnupg", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.kube", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/Library/Keychains", HOME, CACHE),
+ CBM_WS_DENY_SENSITIVE);
+ /* A name that merely contains a listed one is a different directory. */
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.sshconfig", HOME, CACHE), CBM_WS_ALLOW);
+ PASS();
+}
+
+/* Indexing a tree holding the cache would absorb every other project's graph
+ * database, so this is absolute rather than overridable. */
+TEST(ws_cache_holding_roots_are_absolutely_denied) {
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.cache", HOME, CACHE), CBM_WS_DENY_ABSOLUTE);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.cache/codebase-memory-mcp", HOME, CACHE),
+ CBM_WS_DENY_ABSOLUTE);
+ /* A sibling of the cache is not an ancestor of it. */
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.cachex", HOME, CACHE), CBM_WS_ALLOW);
+ PASS();
+}
+
+TEST(ws_windows_system_trees_are_sensitive) {
+ ASSERT_EQ(cbm_workspace_classify_root("C:/Windows", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("C:/Users", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("C:/ProgramData", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("C:/Program Files/app", HOME, CACHE),
+ CBM_WS_DENY_SENSITIVE);
+ /* Case-insensitive: NTFS is, so a case-flipped name must not slip past. */
+ ASSERT_EQ(cbm_workspace_classify_root("C:/WINDOWS", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ ASSERT_EQ(cbm_workspace_classify_root("C:/users/dev/.SSH", HOME, CACHE), CBM_WS_DENY_SENSITIVE);
+ PASS();
+}
+
+/* POSIX is case-sensitive, so a differently-cased directory is a different one
+ * and must not be refused. */
+TEST(ws_posix_matching_is_case_sensitive) {
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.SSH", HOME, CACHE), CBM_WS_ALLOW);
+ PASS();
+}
+
+/* Absent injected context, the checks that depend on it simply do not fire —
+ * they must not crash or deny everything. */
+TEST(ws_null_context_disables_dependent_checks) {
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev", NULL, NULL), CBM_WS_ALLOW);
+ ASSERT_EQ(cbm_workspace_classify_root("/Users/dev/.cache", NULL, NULL), CBM_WS_ALLOW);
+ /* Depth and volume rules are context-free and still apply. */
+ ASSERT_EQ(cbm_workspace_classify_root("/etc", NULL, NULL), CBM_WS_DENY_TOO_SHALLOW);
+ ASSERT_EQ(cbm_workspace_classify_root("/", NULL, NULL), CBM_WS_DENY_ABSOLUTE);
+ PASS();
+}
+
+TEST(ws_every_verdict_has_a_reason) {
+ ASSERT_NOT_NULL(cbm_workspace_verdict_reason(CBM_WS_ALLOW));
+ ASSERT_NOT_NULL(cbm_workspace_verdict_reason(CBM_WS_DENY_TOO_SHALLOW));
+ ASSERT_NOT_NULL(cbm_workspace_verdict_reason(CBM_WS_DENY_ABSOLUTE));
+ ASSERT_NOT_NULL(cbm_workspace_verdict_reason(CBM_WS_DENY_SENSITIVE));
+ /* Reasons are user-facing; a bare enum name would not help anyone. */
+ ASSERT_TRUE(strlen(cbm_workspace_verdict_reason(CBM_WS_DENY_TOO_SHALLOW)) > 20);
+ PASS();
+}
+
+SUITE(workspace) {
+ RUN_TEST(ws_depth_counts_components_below_the_volume);
+ RUN_TEST(ws_volume_roots_are_absolutely_denied);
+ RUN_TEST(ws_non_absolute_paths_are_denied);
+ RUN_TEST(ws_posix_top_level_trees_are_too_shallow);
+ RUN_TEST(ws_legitimate_shallow_roots_are_allowed);
+ RUN_TEST(ws_home_itself_is_sensitive_but_subdirs_are_fine);
+ RUN_TEST(ws_credential_directories_are_sensitive_at_any_depth);
+ RUN_TEST(ws_cache_holding_roots_are_absolutely_denied);
+ RUN_TEST(ws_windows_system_trees_are_sensitive);
+ RUN_TEST(ws_posix_matching_is_case_sensitive);
+ RUN_TEST(ws_null_context_disables_dependent_checks);
+ RUN_TEST(ws_every_verdict_has_a_reason);
+}