MCPcopy
hub / github.com/Fission-AI/OpenSpec / writeChangeMetadata

Function writeChangeMetadata

src/utils/change-metadata.ts:53–84  ·  view source on GitHub ↗
(
  changeDir: string,
  metadata: ChangeMetadata,
  projectRoot?: string
)

Source from the content-addressed store, hash-verified

51 * @throws ChangeMetadataError if validation fails or write fails
52 */
53export function writeChangeMetadata(
54 changeDir: string,
55 metadata: ChangeMetadata,
56 projectRoot?: string
57): void {
58 const metaPath = path.join(changeDir, METADATA_FILENAME);
59
60 // Validate schema exists
61 validateSchemaName(metadata.schema, projectRoot);
62
63 // Validate with Zod
64 const parseResult = ChangeMetadataSchema.safeParse(metadata);
65 if (!parseResult.success) {
66 throw new ChangeMetadataError(
67 `Invalid metadata: ${parseResult.error.message}`,
68 metaPath
69 );
70 }
71
72 // Write YAML file
73 const content = yaml.stringify(parseResult.data);
74 try {
75 fs.writeFileSync(metaPath, content, 'utf-8');
76 } catch (err) {
77 const ioError = err instanceof Error ? err : new Error(String(err));
78 throw new ChangeMetadataError(
79 `Failed to write metadata: ${ioError.message}`,
80 metaPath,
81 ioError
82 );
83 }
84}
85
86/**
87 * Reads change metadata from .openspec.yaml in the change directory.

Callers 2

createChangeFunction · 0.85

Calls 1

validateSchemaNameFunction · 0.85

Tested by

no test coverage detected