0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

A bounded SHA-256 inventory for design exports, with eight local tests

0
Posted at

These are project-associated, AI-assisted engineering notes. The executable example below inventories explicitly selected local files; it is not an image validator, a Roblox approval checker or a report of product-user outcomes. Eight local fixture tests passed for the example. They exercise the Python utility, not the associated browser editor or a real clothing upload.

Official social preview of the associated browser studio

The small problem: which files did we hand over?

A design handoff can contain an editable project, an exported image and a short review note. Similar filenames make it easy to send an old export alongside a newer project. Before arguing about whether two previews look different, it can help to answer a smaller question: are these the same bytes as the files recorded in the handoff? A compact inventory gives that question an explicit input and a reproducible output.

The example deliberately avoids scanning a directory tree. A caller supplies one directory and a short list of relative filenames. That makes the intended scope visible in a command and avoids accidentally including every unrelated file in a working folder. The utility does not upload anything, change the inputs, parse an image or decide whether a project can be restored. Those omissions are part of its contract, not unfinished claims about its capabilities.

Decide what each record means

Each record contains the caller's relative path, the number of bytes read and a SHA-256 digest. The top-level schema number identifies this small JSON shape. A digest can support a later byte-for-byte comparison, but it does not tell us whether the image depicts the intended outfit, whether a reference was licensed, or whether a destination service will accept it. Do not turn the presence of a familiar hash algorithm into a broader assurance.

An editable backup and an exported image also have different jobs. Record both if the next person needs to make layer changes as well as inspect a finished image. Giving a PNG a filename containing the word project does not restore the original editing state. Keep a short human explanation of the intended garment and revision alongside the machine-readable inventory, because a digest does not explain why a change was made.

Keep inputs explicit and bounded

The implementation accepts between one and twenty names. Absolute names and parent-directory components are rejected. Resolved paths must remain inside the chosen directory, must identify files, and must not repeat a resolved path already used in the same call. These checks help catch ordinary handoff mistakes such as including the same file twice or accidentally selecting the parent folder.

It reads at most the configured limit plus one byte from each file and rejects an oversized input rather than claiming a digest of the entire file. The default limit is thirty-two mebibytes per artifact. This is a small local convenience for stable, trusted folders, not a filesystem security sandbox. It does not promise protection against concurrent replacements, all hard-link aliases, network-filesystem surprises or an adversary changing the tree between checks.

The utility

Save the following as artifact_inventory.py. It uses the Python standard library and can run on Python 3.10 or newer. Its command-line output goes to standard output, leaving the source files untouched. Run it only on artifacts you have deliberately selected, not on browser profiles, password files, session stores or a directory containing unrelated private material.

"""Inventory explicit trusted local artifacts; not a format validator or sandbox."""
from pathlib import Path
import hashlib
import json
import sys


def inventory(root, names, max_bytes=32 * 1024 * 1024):
    base = Path(root).resolve(strict=True)
    if not base.is_dir() or not 1 <= len(names) <= 20 or max_bytes < 1:
        raise ValueError('Use a directory, 1-20 names, and a positive size limit')
    seen = set()
    rows = []
    for name in names:
        relative = Path(name)
        if relative.is_absolute() or '..' in relative.parts:
            raise ValueError('Names must be relative and must not contain ..')
        path = (base / relative).resolve(strict=True)
        if not path.is_relative_to(base) or not path.is_file() or path in seen:
            raise ValueError('Expected distinct files inside the selected directory')
        seen.add(path)
        with path.open('rb') as stream:
            data = stream.read(max_bytes + 1)
        if len(data) > max_bytes:
            raise ValueError('Artifact exceeds the size limit')
        rows.append({'path': relative.as_posix(), 'bytes': len(data),
                     'sha256': hashlib.sha256(data).hexdigest()})
    return {'schema': 1, 'files': rows}


if __name__ == '__main__':
    if len(sys.argv) < 3:
        raise SystemExit('Usage: python artifact_inventory.py DIRECTORY FILE [FILE ...]')
    print(json.dumps(inventory(sys.argv[1], sys.argv[2:]), indent=2))

The path in a record is relative to the chosen directory, not an absolute home-directory path. That is usually a better handoff identifier, but relative filenames can still reveal private information. Review the inventory before sharing it. The utility is intentionally not a privacy filter: selecting a sensitive file remains a mistake even if the program can compute its digest correctly.

Exercise the contract with local fixtures

The tests below use a temporary directory and ordinary fixture bytes. In particular, the file called export.png is deliberately not a valid PNG. That is useful here because the contract concerns byte inventories, not image decoding. A passing test must not be described as evidence that an image format, an editor export or an avatar design passed validation.

The cases cover a known digest and length, stable repeated reads, a changed file, a missing name, a parent-directory path, a duplicate normalized path, a size-limit violation and a directory supplied instead of a file. This is a bounded set of examples, not a proof of every filesystem behavior. The actual local run completed all eight tests successfully; no live website or customer export was part of that test run.

import hashlib
from pathlib import Path
import tempfile
import unittest

from artifact_inventory import inventory


class InventoryTests(unittest.TestCase):
    def setUp(self):
        self.tmp = tempfile.TemporaryDirectory()
        self.addCleanup(self.tmp.cleanup)
        self.root = Path(self.tmp.name)
        (self.root / 'export.png').write_bytes(b'fixture bytes, not a real PNG')

    def test_known_digest(self):
        row = inventory(self.root, ['export.png'])['files'][0]
        self.assertEqual(row['sha256'], hashlib.sha256(b'fixture bytes, not a real PNG').hexdigest())
        self.assertEqual(row['bytes'], 29)

    def test_stability(self):
        self.assertEqual(inventory(self.root, ['export.png']), inventory(self.root, ['export.png']))

    def test_changed_bytes(self):
        old = inventory(self.root, ['export.png'])
        (self.root / 'export.png').write_bytes(b'changed')
        self.assertNotEqual(old['files'][0]['sha256'], inventory(self.root, ['export.png'])['files'][0]['sha256'])

    def test_missing(self):
        with self.assertRaises(FileNotFoundError):
            inventory(self.root, ['missing.png'])

    def test_parent_path(self):
        with self.assertRaises(ValueError):
            inventory(self.root, ['../outside.png'])

    def test_duplicate(self):
        with self.assertRaises(ValueError):
            inventory(self.root, ['export.png', './export.png'])

    def test_size_limit(self):
        with self.assertRaises(ValueError):
            inventory(self.root, ['export.png'], max_bytes=4)

    def test_directory_entry(self):
        with self.assertRaises(ValueError):
            inventory(self.root, ['.'])


if __name__ == '__main__':
    unittest.main()

Place the test file beside the utility and run unittest discovery from that directory. The changed-bytes case matters because it distinguishes repeatability from a stale hard-coded result. The missing-file and directory cases matter because a caller should receive an error rather than a reassuring-looking partial record for something that was never read as an ordinary file.

Compare two handoffs without overinterpreting the result

First keep the files stable while producing an inventory. If another application is still saving a project, wait for that operation to finish or copy the intended artifacts into a separate handoff folder. A digest computed during a write is not a transaction snapshot. The utility does not lock the editor or coordinate with another process, so the surrounding workflow must provide that stability.

Next compare the corresponding relative path, byte count and digest with the earlier record. A mismatch means that the recorded bytes differ; it does not explain which design decision changed. A match supports the narrower conclusion that the two reads produced matching byte content under the assumptions of the comparison. It does not certify authorship, authenticity, licensing or successful restoration of the project.

Finally reopen the editable artifact in its intended application when that is part of the handoff requirement. Inspect the export separately and write down the remaining visual or destination-platform question. Keeping these observations separate makes debugging easier: a missing layer is an editing-state issue, a different digest is a byte-comparison observation, and a rejected upload is a destination response. One should not silently stand in for the others.

A clothing-export use case

The associated roblox clothing exporter is Roblox Shirt Maker, an independent browser studio with templates, direct editing, optional credit-based AI generation, an R6 preview and PNG downloads. It distinguishes classic shirts and pants, which export 585 by 559 images using their respective garment regions, from graphic T-shirts, which export transparent 512 by 512 graphics. The inventory utility neither decodes nor verifies any of those layouts.

Core editing, previews, project saving and downloads are free; optional AI work uses account credits and has separate paid offers. Roblox Shirt Maker is not affiliated with Roblox. Exporting an image does not upload or approve clothing there, and Roblox's requirements, possible fees and moderation remain separate. The product is included transparently as a project-associated context for the file-handoff problem, not as a claimed model integration or independent endorsement.

Use the smallest useful inventory

A practical package normally needs understandable files, an explicit revision, a short note about the intended next step and only the metadata needed for comparison. Do not collect more private material because a script makes it convenient. If a recipient only needs an exported image, decide whether they need the editable backup as well instead of automatically publishing the entire working folder.

The useful result is a narrower, better-defined question that another person can answer. This utility can tell us what selected bytes were recorded and can reject several common input mistakes. It cannot tell us that a design is complete. Keeping that boundary explicit is more valuable than attaching a technical-looking digest to a handoff and allowing everyone to assume the remaining work has somehow been done.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?