<commit_before>import { action, computed, observable } from "mobx";
import UiState from "./UiState";

class PlaybackState {
  @observable isPlaying = false;
  @observable currentPlayingIndex = 0;
  @observable currentRunningTest = null;
  @observable commandsCount = 0;
  @observable commandState = new Map();
  @observable runs = 0;
  @observable failures = 0;
  @observable hasFailed = false;

  constructor() {
    this._currentRunningSuite = null;
    this._testsToRun = [];
  }

  @computed get finishedCommandsCount() {
    let counter = 0;

    this.commandState.forEach(({ state }) => {
      if (state !== CommandStates.Pending) {
        counter++;
      }
    });

    return counter;
  }

  @action.bound startPlayingSuite() {
    const { suite } = UiState.selectedTest;
    if (this._currentRunningSuite !== suite) {
      this.resetState();
      this._currentRunningSuite = suite.id;
    }
    this._testsToRun = [...suite.tests];
    this.playNext();
  }

  @action.bound startPlaying() {
    const { test } = UiState.selectedTest;
    if (this._currentRunningSuite || !this.currentRunningTest || this.currentRunningTest.id !== test.id) {
      this.resetState();
      this.currentRunningTest = test;
    }
    this.runs++;
    this.hasFailed = false;
    this.commandsCount = test.commands.length;
    this.isPlaying = true;
  }

  @action.bound playNext() {
    this.currentRunningTest = this._testsToRun.shift();
    this.runs++;
    this.hasFailed = false;
    this.isPlaying = true;
  }

  @action.bound stopPlaying() {
    this.isPlaying = false;
  }

  @action.bound abortPlaying() {
    this.isPlaying = false;
    this._testsToRun = [];
  }

  @action.bound finishPlaying() {
    this.isPlaying = false;
    if (this._testsToRun.length) {
      this.playNext();
    }
  }

  @action.bound setPlayingIndex(index) {
    this.currentPlayingIndex = index;
  }

  @action.bound setCommandState(commandId, state, message) {
    if (state === CommandStates.Failed) {
      this.hasFailed = true;
      this.failures++;
    }
    this.commandState.set(commandId, { state, message });
  }

  @action.bound clearCommandStates() {
    this.commandState.clear();
  }

  @action.bound resetState() {
    this.clearCommandStates();
    this.currentPlayingIndex = 0;
    this.runs = 0;
    this.failures = 0;
    this.hasFailed = false;
  }
}

export const CommandStates = {
  Passed: "passed",
  Failed: "failed",
  Pending: "pending"
};

if (!window._playbackState) window._playbackState = new PlaybackState();

export default window._playbackState;
<commit_msg>maybe the previous one failed<commit_after>import { action, computed, observable } from "mobx";
import UiState from "./UiState";

class PlaybackState {
  @observable isPlaying = false;
  @observable currentPlayingIndex = 0;
  @observable currentRunningTest = null;
  @observable commandsCount = 0;
  @observable commandState = new Map();
  @observable runs = 0;
  @observable failures = 0;
  @observable hasFailed = false;

  constructor() {
    this._currentRunningSuite = null;
    this._testsToRun = [];
  }

  @computed get finishedCommandsCount() {
    let counter = 0;

    this.commandState.forEach(({ state }) => {
      if (state !== CommandStates.Pending) {
        counter++;
      }
    });

    return counter;
  }

  @action.bound startPlayingSuite() {
    const { suite } = UiState.selectedTest;
    if (this._currentRunningSuite !== suite) {
      this.resetState();
      this._currentRunningSuite = suite.id;
    }
    this._testsToRun = [...suite.tests];
    this.playNext();
  }

  @action.bound startPlaying() {
    const { test } = UiState.selectedTest;
    if (this._currentRunningSuite || !this.currentRunningTest || this.currentRunningTest.id !== test.id) {
      this.resetState();
      this.currentRunningTest = test;
    }
    this.runs++;
    this.hasFailed = false;
    this.commandsCount = test.commands.length;
    this.isPlaying = true;
  }

  @action.bound playNext() {
    this.currentRunningTest = this._testsToRun.shift();
    this.runs++;
    this.isPlaying = true;
  }

  @action.bound stopPlaying() {
    this.isPlaying = false;
  }

  @action.bound abortPlaying() {
    this.isPlaying = false;
    this._testsToRun = [];
  }

  @action.bound finishPlaying() {
    this.isPlaying = false;
    if (this._testsToRun.length) {
      this.playNext();
    }
  }

  @action.bound setPlayingIndex(index) {
    this.currentPlayingIndex = index;
  }

  @action.bound setCommandState(commandId, state, message) {
    if (state === CommandStates.Failed) {
      this.hasFailed = true;
      this.failures++;
    }
    this.commandState.set(commandId, { state, message });
  }

  @action.bound clearCommandStates() {
    this.commandState.clear();
  }

  @action.bound resetState() {
    this.clearCommandStates();
    this.currentPlayingIndex = 0;
    this.runs = 0;
    this.failures = 0;
    this.hasFailed = false;
  }
}

export const CommandStates = {
  Passed: "passed",
  Failed: "failed",
  Pending: "pending"
};

if (!window._playbackState) window._playbackState = new PlaybackState();

export default window._playbackState;

{'fraction_non_alphanumeric': 0.13254184507590502, 'fraction_numerical': 0.003114052160373686, 'mean_word_length': 3.1079136690647484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7303570', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1603, 'n_words': 326}