Repository: Azure/azure-rest-api-specs
File: eng/tools/openapi-diff-runner/src/utils/oad-message-processor.ts (TypeScript)

Code before:
}

/**
 * Create a deterministic key for an OAD message to enable deduplication
 */
export function createMessageKey(message: OadMessage): string {
  // Create a deterministic key based on message properties that define uniqueness
  // Adjust these properties based on what makes an OadMessage unique
  return JSON.stringify({
    code: message.code,
    message: message.message,
    type: message.type,
    mode: message.mode,
    newLocation: message.new?.location,
    oldLocation: message.old?.location,
    newPath: message.new?.path,
    oldPath: message.old?.path,
    // Add other properties that determine uniqueness
  });
}

/**
 * Append a message to the log file
 */
export async function appendToLogFile(logFilePath: string, msg: string): Promise<void> {
  await fs.promises.appendFile(logFilePath, msg + "\n");
  await logMessageSafeAsync("oad-message-processor.appendMsg: " + msg);
}

/**
 * Append markdown content to the log file
 */
export async function appendMarkdownToLog(
  context: OadMessageProcessorContext,
  errorMsg: string,
  levelType = "Error",
): Promise<void> {
  const markdownRecord = JSON.stringify({
    type: "Markdown",
    mode: "append",
    level: levelType,
    message: errorMsg,
    time: new Date(),
  });
  await appendToLogFile(context.logFilePath, markdownRecord);
}

/**
 * Process and deduplicate OAD messages, then append to log
 * This function is invoked by BreakingChangeDetector.doBreakingChangeDetection()
 */

Review comment (suggestion):
```suggestion
  fs.appendFileSync(logFilePath, msg);
  fs.appendFileSync(logFilePath, "\n");
  ```

Code after:
}

/**
 * Create a deterministic key for an OAD message to enable deduplication
 */
export function createMessageKey(message: OadMessage): string {
  // Create a deterministic key based on message properties that define uniqueness
  // Adjust these properties based on what makes an OadMessage unique
  return JSON.stringify({
    code: message.code,
    message: message.message,
    type: message.type,
    mode: message.mode,
    newLocation: message.new?.location,
    oldLocation: message.old?.location,
    newPath: message.new?.path,
    oldPath: message.old?.path,
    // Add other properties that determine uniqueness
  });
}

/**
 * Append a message to the log file
 */
export async function appendToLogFile(logFilePath: string, msg: string): Promise<void> {
  fs.appendFileSync(logFilePath, msg);
  fs.appendFileSync(logFilePath, "\n");
  await logMessageSafeAsync("oad-message-processor.appendMsg: " + msg);
}

/**
 * Append markdown content to the log file
 */
export async function appendMarkdownToLog(
  context: OadMessageProcessorContext,
  errorMsg: string,
  levelType = "Error",
): Promise<void> {
  const markdownRecord = JSON.stringify({
    type: "Markdown",
    mode: "append",
    level: levelType,
    message: errorMsg,
    time: new Date(),
  });
  await appendToLogFile(context.logFilePath, markdownRecord);
}

/**
 * Process and deduplicate OAD messages, then append to log
 * This function is invoked by BreakingChangeDetector.doBreakingChangeDetection()