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
20 changes: 16 additions & 4 deletions client/normative/normative_precedence.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,22 @@ def _sentences(text):
if part.strip()]


def _replacement(ledger, standard_id="", revision=""):
def _names(standard_id="", revision="", binding=None):
"""The bound standards, the active one first, for a reader."""
names = [" ".join(part for part in (standard_id, revision) if part)]

if isinstance(binding, dict):
names += [" ".join(str(item.get(key) or "") for key in ("standard_id", "revision")).strip()
for item in binding.get("companions") or () if isinstance(item, dict)]

names = [name for name in names if name]

return " or ".join(names) or "the bound standard"


def _replacement(ledger, standard_id="", revision="", binding=None):
"""What is put in place of a requirement nothing retrieved supports."""
name = " ".join(part for part in (standard_id, revision) if part) or (
"the bound standard")
name = _names(standard_id, revision, binding)
read = sorted(ledger.sections,
key=lambda section: [int(part) for part in section.split(".")])

Expand All @@ -296,7 +308,7 @@ def sanitize(answer, ledger, *, standard_id="", revision="", binding=None):
if not problems:
return text, []

note = _replacement(ledger, standard_id, revision)
note = _replacement(ledger, standard_id, revision, binding)
replaced = []
placed = False

Expand Down
16 changes: 16 additions & 0 deletions client/tests/test_normative_precedence.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ def test_what_replaces_it_says_where_a_requirement_comes_from(self):
answer)


class TheNoteNamesEveryBoundStandard(unittest.TestCase):
"""With a companion bound, the note named only the active standard: "No
requirement of ARM-DDI0487 M.c is stated here", over an answer that cited
the GIC specification throughout."""

def test_companions_are_named_after_the_active_standard(self):
binding = {"standard_id": "ARM-DDI0487", "revision": "M.c",
"companions": [{"standard_id": "ARM-IHI0069", "revision": "H.b"}]}

self.assertEqual(normative_precedence._names("ARM-DDI0487", "M.c", binding),
"ARM-DDI0487 M.c or ARM-IHI0069 H.b")
self.assertEqual(normative_precedence._names("ARM-DDI0487", "M.c"),
"ARM-DDI0487 M.c")
self.assertEqual(normative_precedence._names(), "the bound standard")


class DeviationsAreReportable(unittest.TestCase):
"""CASE 2 -- the implementation contradicts the standard."""

Expand Down
23 changes: 23 additions & 0 deletions scripts/docker/spear
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,28 @@ NAME="spear-$(printf '%s' "${WORKDIR##*/}" | tr -c 'A-Za-z0-9_.-' '-')-$$"

MEMORY="${SPEAR_CONTAINER_MEMORY:-$(awk '/^MemTotal:/ { printf "%dm", $2 * 3 / 4 / 1024 }' /proc/meminfo)}"

# chromadb opens the image's index read-write, and overlayfs then copies the
# whole database into each new container: some 25 GB and tens of seconds at
# every start, long enough for chromadb to give up waiting. A named volume
# holds it instead, filled from the image once and reused while the image
# stays the same; volumes of earlier images are removed when not in use.

INDEX=()
SHIPPED="$(docker image inspect -f '{{range .Config.Env}}{{println .}}{{end}}' "$IMAGE" 2>/dev/null \
| sed -n 's/^SPEAR_SHIPPED_DB_PATH=//p')"

if [ -n "$SHIPPED" ]; then
VOLUME="spear-index-$(docker image inspect -f '{{.Id}}' "$IMAGE" | cut -d: -f2 | cut -c1-12)"

for old in $(docker volume ls -q --filter name=spear-index-); do
[ "$old" = "$VOLUME" ] || docker volume rm "$old" >/dev/null 2>&1 || true
done

docker volume inspect "$VOLUME" >/dev/null 2>&1 \
|| echo "spear: copying the image's index into the volume $VOLUME, once" >&2
INDEX=(-v "$VOLUME:$SHIPPED")
fi

# The three --security-opt are what bubblewrap, the harness's sandbox, needs
# to start inside a container; without them it refuses every command.

Expand All @@ -352,6 +374,7 @@ exec docker run --rm --name "$NAME" "${TTY[@]}" \
-e "SPEAR_STATE_DIR=/state" \
-e "HOME=/state/home" \
-v "$STATE:/state" \
"${INDEX[@]}" \
"${BINDS[@]}" \
-w "$WORKDIR" \
"${ENTRY[@]}" \
Expand Down
Loading